Question: I know that ( ) is used as a tuple (variable containing multiple values) & [
] is for a list in python. My question is in the following scenario when I used a tuple the code worked but when I used a list it showed a typeError. Why? Plus, Why do we use string formatting anyway? What is actually string formatting and what does it do? If it is string formatting then why is there a %d that formats integers?
The First attempt with tuple:
data = ("John", "Doe", 53.44) format_string = "Hello %s %s. Your current balance is $%s." print(format_string % data)
Hello John Doe. Your current balance is $53.44.
The second attempt with list:
data = ["John", "Doe", 53.44] format_string = "Hello %s %s. Your current balance is $%s." print(format_string % data)
TypeError: not enough arguments for format string
My question is we can use lists in string formatting then why doesn’t it work here?