Python 3 The Standard Type Hierarchy
In Python 3 types of data type
number |
string |
boolean |
int,float |
str |
bool |
12,18.9 |
' ' or " " |
True, False |
userName="Ashu"
userAge=29
userSalary=19.9
userBool=True
userList=['Ashu','pankaj','aman','aman']
userTuple=('Ashu','pankaj','aman')
userSet={'Ashu','pankaj','aman'}
userDict={'A1':'Ashu','B1':'pankaj','C1':'aman'}
print(type(userName))
print(type(userAge))
print(type(userSalary))
print(type(userBool))
print(type(userList))
print(type(userTuple))
print(type(userSet))
print(type(userDict))
<class `str`>
<class `int`>
<class `float`>
<class `bool`>
<class `list`>
<class `tuple`>
<class `set`>
<class `dict`>
How many ways to formated data in python ?
In Python formatting the date in two way
String |
Integer |
Float |
Float |
%s |
%d |
%f |
%g |
|
|
it only print 17 digit |
Only print 6 digit |
def getValueFrom(id,name,marks):
# substitute must be same order
print("Student ID=%d Student Name=%s Student Marks=%g"%(id1,name,marks))
id1=int(input("Enter Student ID: "))
name=input("Enter Student Name: ")
marks=float(input("Enter Student Marks: "))
getValueFrom(id1,name,marks)
Enter Student ID: 1002
Enter Student Name: Ashutosh
Enter Student Marks: 98.9
Student ID=1002 Student Name=Ashutosh Student Marks=98.9
def getValueFrom(id,name,marks):
#substitute must be same order.Here Type is important
print("Student ID=%d Student Name=%s Student Marks=%g"%(id1,name,marks))
#Here in this case Type is not important
print("Student ID={} Student Name={} Student Marks={}".format(id1,name,marks))
print("Student ID={0} Student Name={1} Student Marks={2}".format(id1,name,marks))
id1=int(input("Enter Student ID: "))
name=input("Enter Student Name: ")
marks=float(input("Enter Student Marks: "))
getValueFrom(id1,name,marks)
Enter Student ID: 1002
Enter Student Name: ashu
Enter Student Marks: 98.78
Student ID=1002 Student Name=ashu Student Marks=98.78
Student ID=1002 Student Name=ashu Student Marks=98.78
Student ID=1002 Student Name=ashu Student Marks=98.78