+ 1

Here to print dictionary %(name, number) is used, why % is used instead of common?

phonebook = {"John" : 938477566,"Jack" : 938377264,"Jill" : 947662781} for name, number in phonebook.items(): print("Phone number of %s is %d" % (name, number))

9th May 2021, 5:45 AM
Kavya N
Kavya N - avatar
1 Odpowiedź
+ 1
The is the C-style string interpolation. I found this article that explains it https://www.informit.com/articles/article.aspx?p=28790&seqNum=2 This is the same as doing print("Phone number of {} is {}".format(name, number)) And print(f"Phone number of {name} is {number}")
9th May 2021, 6:17 AM
XXX
XXX - avatar