0

what is the meaning of code

print("{0} - {1}%".format(char, round(perc, 2))) in this line i donot understand what is work and meaning of {0}-{1}% can u just clarify me detail about it

20th Feb 2017, 10:38 AM
Chandan Kumar Sahoo
Chandan Kumar Sahoo - avatar
2 ответов
+ 1
Curly brackets in the string are replaced by the parameters of format() method ( without need to cast them to string explicitly ): print("A sort of {} template... not only for string but for any type of variables: {}".format("little",42); ... output: A sort of little template... not only for string but for any type of variables: 42 If you change order of parameters, you change the order of the replacements, so you can specify the index of the parameter to use: print("A sort of {1} template... not only for string but for any type of variables: {0}".format(42,"little"); ... will output same ^^
20th Feb 2017, 10:51 AM
visph
visph - avatar
0
1. ill tell you to go and repeat dictionnaries. 2. {0} and {1} are like placeholder for arguments that are in this case "char" and the other one is a bit trickier: round(x,2) is a number with two digits after comma. And perc is like x just a variable. So {0} is char and {1} is the rounded number of perc
20th Feb 2017, 10:44 AM
S0muchM3NY