Basic data type in Python-
followings are the basic data type in python:-
1. bool
2. int
3. float
4. str
5. list
6. set
7. tuple
8. dict
Bool
Contain boolean values i.e. true or false
example :-
a=True
print(a)
// output - True
________________________________________Int
contain integer value
example:-
a=1234
print(a)
print(a+34)
// output - 1234
1268
________________________________________Float
contain floating value
example:-
a=1.2
print(a)
print(type(a))
// output - 1.2
________________________________________str
it is use to create a string data type in python
example :-
s=str("Mytext")
print(s)
________________________________________list
it is a mutable collection of elements of different different type
example :-
l=list[1,2,3]
print(l)
l=[1,2,"mytext"]
print(l)
// output - 1,2,3
1,2,"mytext"
________________________________________Set
It is immutable collection of elements and set do promote duplicacy
example :-
s=set([1,2,3,1,2])
print(s)
// output - 1,2,3
________________________________________Dict
It's a two dimensional arrangement of elements of an elements in the form of keys and values.
d={1:"fisrt",2:"second",3:"third"}
print(d)
print(d[2])
//output - {1: 'fisrt', 2: 'second', 3: 'third'}
second
Immutable datatype-
The datatype which are not promote insertion at their index value at runtime are called as immutable datatype.
Example :- lets we have a string s="Mytext" and I try to change index 1 value like s[1]="s" , then it will give error
bool,int, float, string, tuple are the immutable datatype
Mutable datatype-
List, set and dict are the mutable data type in python
Example:-
L=list(1,2,3,4)
L[1]="8"
// list will become L=[1,8,3,4]