Python Forum

Full Version: Operator meaning explanation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I have a question.

name = "Giraffe"
score = 80
print("%s result as %d" % (name, score))
Output:
Giraffe result as 80
What meaning for the % sign place before (name, score)?

Thanks
It's just the old way of allowing you to substitute the values of those variables for the placeholders (%s and %d) in the string, as the output shows. These days, you should be using f-strings, though.
print("%s result as %d" % (name, score))
is old style print statement, you should use f-string:
print(f"{name} result as {score}")
(Jul-31-2021, 07:52 AM)ndc85430 Wrote: [ -> ]It's just the old way of allowing you to substitute the values of those variables for the placeholders (%s and %d) in the string, as the output shows. These days, you should be using f-strings, though.

Thank you so much , I learn new thing outside the book. Wink
(Jul-31-2021, 08:34 AM)Larz60+ Wrote: [ -> ]print("%s result as %d" % (name, score))
is old style print statement, you should use f-string:
print(f"{name} result as {score}")

Thank you so much, learn new thing. Dance it means my book is old version.. Big Grin Big Grin Big Grin