Basic data type in python by R4R Team

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]



Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!