+ 2
print("{0} - {1}".format(char,round(perc,2)
Can anyone explain what does this piece of code means????
2 Réponses
+ 6
.format() method takes its arguments and inserts them into the string that calls it, at {index or key}. So it replaces {0} with its first argument, char; since it's not in quotes, it'll look for a variable named char. Then it replaces {1} with round(perc,2) ; round for its part returns the variable perc rounded to 2 decimal places.
In other words, this prints the values of char and perc (rounded) with a hyphen separating them.