25s 25d python

Solutions on MaxInterview for 25s 25d python by the best coders in the world

showing results for - " 25s 25d python"
Kylee
22 Apr 2019
1name = "Gandalf"
2extendedName = "the Grey"
3age = 84
4IQ = 149.9
5print('type(name):', type(name)) #type(name): <class 'str'>
6print('type(age):', type(age))   #type(age): <class 'int'>   
7print('type(IQ):', type(IQ))     #type(IQ): <class 'float'>   
8
9print('%s %s\'s age is %d with incredible IQ of %f ' %(name, extendedName, age, IQ)) #Gandalf the Grey's age is 84 with incredible IQ of 149.900000 
10
11#Same output can be printed in following ways:
12
13
14print ('{0} {1}\'s age is {2} with incredible IQ of {3} '.format(name, extendedName, age, IQ))          # with help of older method
15print ('{} {}\'s age is {} with incredible IQ of {} '.format(name, extendedName, age, IQ))          # with help of older method
16
17print("Multiplication of %d and %f is %f" %(age, IQ, age*IQ)) #Multiplication of 84 and 149.900000 is 12591.600000          
18
19#storing formattings in string
20
21sub1 = "python string!"
22sub2 = "an arg"
23
24a = "i am a %s" % sub1
25b = "i am a {0}".format(sub1)
26
27c = "with %(kwarg)s!" % {'kwarg':sub2}
28d = "with {kwarg}!".format(kwarg=sub2)
29
30print(a)    # "i am a python string!"
31print(b)   # "i am a python string!"
32print(c)    # "with an arg!"
33print(d)   # "with an arg!"