-1

I am new to python and trying to learn the basic

just learned how to format string today and couldn't figure out what is wrong with this line of codes

data = ["Zac", "poor fella", 100]
format_string = "%s is a %s, his bank account has $%s."
print(format_string % data)

my goal is trying to print out "John is a poor fella, his bank account has $100."

But when I run it it came back with "Python TypeError: not enough arguments for format string"

Please let me know what I did wrong, thanks!

I tried putting parentheses in between format_string and data

1
  • The arguments must be provided as a tuple, not as a list. Use data = (...), not data = [...]. Commented Nov 24, 2023 at 22:09

1 Answer 1

0

You have to use tuple instead of list and use % to format the string:

data = ["Zac", "poor fella", 100]
print("%s is a %s, his bank account has $%s." % tuple(data))

Result: Zac is a poor fella, his bank account has $100.

You could use modern f-string formatting:

data = ["Zac", "poor fella", 100]
print(f"{data[0]} is a {data[1]}, his bank account has ${data[2]}.")
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.