Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String formatting in Python for today standards [duplicate]

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?

like image 677
Felipe Miotto Avatar asked Dec 06 '25 03:12

Felipe Miotto


1 Answers

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

print(f"Guess number {variable1} of {variable2}")
like image 64
CDJB Avatar answered Dec 07 '25 17:12

CDJB