+ 2

print("{0} - {1}".format(char,round(perc,2)

Can anyone explain what does this piece of code means????

11th May 2023, 5:45 AM
Ahmad Mahir Shadab
Ahmad Mahir Shadab - avatar
1 Antwort
+ 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.
11th May 2023, 6:00 AM
Orin Cook
Orin Cook - avatar