-1

while I read this

that has this code

We can also do that this way:

We'd have 500000 beans, 500 jars, and 5 crates.

when I revised to pep 498

print("We can also do that this way:")
print(f"We'd have {secret_formula(start_point)} beans, {secret_formula(start_point)} jars, and {secret_formula(start_point)} crates.")

it print this

We can also do that this way:

We'd have (500000, 500, 5) beans, (500000, 500, 5) jars, and (500000, 500, 5) crates.

1
  • You might like: print("We'd have {} beans, {} jars, and {} crates.".format(*secret_formula(start_point))) Commented Dec 1 at 15:27

1 Answer 1

4

I see you are following LPTHW (Learn Python the Hard Way) tutorial, which I strongly suggest you pick up a different tutorial, as the current one you have has some very interesting opinions and some other issues.

Back to your question: you need to unpack the secret_formula() call to be:

b, j, c = secret_formula(start_point)

print(f"We'd have {b} beans, {j} jars, and {c} crates.")

f-strings are basically just placing the variable in the string to call it and since the secret_formula() returns a tuple, when you fstring just calling the function, it will return and print the tuple.

Sign up to request clarification or add additional context in comments.

3 Comments

Do you have any books on python 3 for me?
how to print this code with f-string? ``` print('{0:_^11}'.format('hello')) ```
@kunjun the same way you would with .format() like this: print(f'{x:_^11}')

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.