Data Structures in Python
List is an mutable data structure
It's a linear data structure.
With index number of elements in List, we can insert or delete elements.
Indexing starts with 0 from left to right and -1 from right to left.
# List program
numbers = [1 , "3" , 4.5 ]
print (type (listVar ))
Tuple is immutable data structure
It's a linear data structure.
With index number of elements in List, we can retrieve elements.
It is ordered collection from left to right in sequences.
Tuples are classified as immutable sequences. Direct change operations cannot be applied to tuples.
Tuples are heterogeneous like Lists. It can store different data types and data structures.
Tuples can't be modified. In case of modification, you need to create copy and change elements.
tupleVar = (1 , 2 , 3 )
print (type (tupleVar ))
Sets is immutable data structure
Sets are unordered. It means it doesn't have indexing for its elements.
Sets elements are unique. Duplicate elements are not allowed.
A set itself may be modified, but the elements contained in the set must be of an immutable type.
setVar = {1 ,2 ,3 }
print (type (setVar ))
Its a key-value data structure.
Value can only be retrived by its asociated key.
Dictionary supports heterogenous structure.
dictVar = {"name" :"rahul" , "age" :5 }
print (type (dictVar ))