There are basic two datatypes in python
1. Immutable datatype : numeric , string , tuple
2. Mutable : list , dictionary , set
Immutable : Content cannot be changed or modified using the indexing operator ( assignment statement )
Mutable : Content can be changed or modified using the indexing operator ( assignment statement )
Numeric : int, float , complex numbers
Sequence : list, string, tuple, range
Mapping : dictionary
Set : set , frozenset
Boolean : is used for making more conditions for 'if' in True and False form
Collections in python :
1) Dictionary :
It is used to map arbitrary keys to value
Only immutable ( content can be changed ) objects can be used as keys to dictionaries
Ex : D = { 'a' : 10 , 'b' : [20, 30] }
2) List :
It can collect multiple values, multiple types of objects and data collection in single variable.
It is mutable. So operation such like remove, append , insert can be done here
Append : to add an item or whole list to the end of an existing list
Extend : to add every items separated by commas to the end of an existing list (due to for loop working behind)
Indexing, slicing can be done here
Indexing : referring to an element position of an iterable within an ordered list
Slicing : is way of retrieving values from a list. use to modify or delete the items of mutable
Ex : L = [1 , 'a' , [ 2 , 'b' ] , ( 3, 4 )]
3) Tuples :
It is immutable
Ex : T = ( 1, 2, 3) or T = 1, 2, 3
Comments
Post a Comment