Concepts

Computer Science - Class 11
Chapter 5 Class 11 - Getting started with python

Data type identifies the type of data values a variable can hold and the operations that can be performed on that data.

Number

Number data type stores numerical values only.

It is further classified into three different types:

Boolean data type (bool) is a subtype of integer . It is a unique data type, consisting of two constants, True and False . Boolean True value is non-zero, non-null and non-empty. Boolean False is the value zero.

Sequence

A Python sequence is an ordered collection of items , where each item is indexed by an integer. The three types of sequence data types available in Python are:

• Strings - String is a group of characters . These characters may be alphabets, digits or special characters including spaces . String values are enclosed either in single quotes or double quotes.

Examples:

1. str1 = ”hello”
2. str2 = ’123’
• Lists - List is a sequence of items separated by commas and the items are enclosed in square brackets [ ].

Examples:

1. list1 = [1,25,”abc”,”Delhi”]
2. list2 = [“India”,”USA”,”UK”]
• Tuples - Tuple is a sequence of items separated by commas and items are enclosed in parenthesis ( ). Once created, we cannot change the tuple.

Examples:

1. tuple1 = (‘a’,1,25,”Noida”)
2. tuple2 = (“Delhi”,”Mumbai”,”Chennai”,”Cochin”)

Set

Set is an unordered collection of items separated by commas and the items are enclosed in curly brackets { } . A set is similar to a list , except that it cannot have duplicate entries. Once created, elements of a set cannot be changed .

Examples:

1. set1 = {1,’a’,34,”Delhi”}
2. set2 = {“Delhi”,”Mumbai”,”Chennai”,”Cochin”}

None

None is a special data type with a single value. It is used to signify the absence of value in a situation. None supports no special operations , and it is neither the same as False nor 0 (zero).

Example:

• var1 = None

Mapping

Mapping is an unordered data type in Python .

There is only one standard mapping data type in Python called a dictionary.

Dictionary

• Dictionary in Python hold data items in key-value pairs.
• Items in a dictionary are enclosed in curly brackets { }.
• Every key is separated from its value using a colon (:) sign.
• The key : value pairs of a dictionary can be accessed using the key.
• The keys are usually strings and their values can be any data type.
• In order to access any value in the dictionary, we have to specify its key in square brackets [ ].

Example:

dict1={‘Fruit’:’Apple’,’Price’:120,’Weight(kg)’:1}

Mutable and Immutable Data Types

 Mutable data types Immutable data types Variables whose values can be changed after they are created and assigned are called mutable. Variables whose values cannot be changed after they are created and assigned are called immutable. When an attempt is made to update the value of an immutable variable, the old variable is destroyed and a new variable is created by the same name in memory

Get live Maths 1-on-1 Classs - Class 6 to 12