Classification of Datatype and Mutability, Immutability
Classification of Datatype and Mutability, Immutability
3.Complex Numbers :
The numbers with real and imaginary *art 5s ter0 t6 be the
complex numbers
It is represented in the form of real + imaginary
Example: k=4+5j where j=√-1
To print only the real part give the code as k.real and for
imaginary give the code as k.imag
If the input is 0+any imaginary part then in the result only
the imaginary part will get displayed
4.Strings:
Strings can be a single character enclosed with single
quotes/ group of characters with single or double quotes /
group f lines with triple or double quotes.
Strings supports indexing. It can be forward or backward
indexing
Forward indexing starts from 0 to n.
Backward indexing from -1
Example: s=”all the best”
T=’j’
W=’logical thinking’
S[1] will give the result as l
5.Lists:
Group of elements are declared in a single variable is
termed as list.
The list is represented using [ ]
List is an ordered list
List allows indexing
Example: L=[8,2,3]
L[2] will give the result as 3
6.Tuples:
Group of elements are declared in a single variable is
termed as tuple.
The tuple is represented using ( )
tuple is an ordered way of representing
tuple allows indexing
Example: T=(8,2,3)
T[1] will give the result as 2
7.Sets:
Group of elements are declared in a single variable is
termed as Set.
Sets are represented using { }
Sets are unordered list
Sets doesn’t support indexing
Sets is the only datatype which doesnot allow duplicate
values. EX: S={5,5,5} while printing the result only {5} will be
the result
While updating the Sets, only the immutable objects can be
updated with the existing set.
8.Dictionary:
Group of elements are declared with key and values in a
single variable is termed as dictionary.
Dictionaries are represented using { key:”value”}
Example: D={1:”apple”,2:”banana”,63:”icecream”}
Dictionary indexing is based on key.
D[63] will give the result as icecream
Key values can be updated/ edited.
-------------------------------------------------------------------------------------------------
MUTABLE AND IMMUTABLE OBJECTS