Day 3
Day 3
output:
Enter ur
age:1212
<class 'str'>
output:
Enter ur
age:1010
<class 'int'>
Note:
eval() function will work with int and float datatype both, when input type is not
knownin advance then, eval() function is recommended.
input():
The input function treats the inputed data as string if the input is included in " "
quotes.Otherwise the data is taken as it is, ie numbers as numbers and strings as
strings.
raw_input():
Always the inputed data is treated as string weather it is enclosed in quotes or not.
Note: deprecated in python 3.
python 3:
input():
Always treats the inputed data as string type.
res=eval(input("Enter an expression
:"))print(res)
output:
Enter an expression
:2+5+10-512
>>>
Examples:
a,b,c=20,22.45,"python"
print(a,b,c)
a=b=c=100
print(a,b,c)
print(id(a))
print(id(b))
print(id(c))
Output:
Enter the value for a :12.56
Error:-Invalid Literal....
x=eval("10+20+30")
print(x,type(x))
res=int(input("Enter an Expression:"))
print(res)
Error:
res=eval(input("Enter an Expression:"))
print(res)
x=raw_input('enter a number')
print(x)
Error:Because it Deprecated in Vertion 3
a,b,c,d=10,20,30,40
print(a,b,c,d)
print(a,b,c,d,sep=":")
//place Holders
a,b,c,d=0,20,30,40
print("a={},b={},c={},d={}".format(a,b,c,d)
name="Rama Krishna"
course="Python"
Inst='Datapro'
fees=6000
print("Hello {} Your Learing {} course from {} institute and fee is {}".format(name,course,Inst,fees))
name="Rama Krishna"
course="Python"
Inst='Datapro'
fees=6000
print("Hello {0} Your Learing {1} course from {2} institute and fee is
{3}".format(name,course,Inst,fees))
print("Hello {0} Your Learing {2} course from {2} institute and fee is
{0}".format(name,course,Inst,fees))
name="Rama Krishna"
course="Python"
Inst='Datapro'
fees=6000
print("Hello {0} Your Learing {1} course from {2} institute and fee is
{3}".format(name,course,Inst,fees))
print("Hello {n} Your Learing {c} course from {I} institute and fee is
{f}".format(n=name,c=course,I=Inst,f=fees))
//formatted String
rno=1001
name="Rama Krishna"
course="Python"
Inst='Datapro'
fees=6000.9023