Felipe Miotto
Felipe Miotto

Reputation: 33

String formatting in Python for today standards

i'm learning python from a book that i bought in 2017 and from a online course at the same time.

The book says that i should format the string like this example;

print("Guess number %d of %d" % (variable1, variable2))

But the online course says that i should format this way;

print("Guess number {} of {}".format(variable1, variable2))

Which one should i use for today programming standards?

Upvotes: 3

Views: 69

Answers (2)

Jay_jen
Jay_jen

Reputation: 44

I'd predict the use are f-strings are aimed at readability. That said, i would say the real answer is which ever one is more readable in your function or whatever.

Upvotes: 1

CDJB
CDJB

Reputation: 14506

Well, from Python 3.6, you can use f-strings:

print(f"Guess number {variable1} of {variable2}")

Upvotes: 4

Related Questions