Python Forum
Operator meaning explanation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Operator meaning explanation
#1
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
Reply
#2
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.
Sherine likes this post
Reply
#3
print("%s result as %d" % (name, score))
is old style print statement, you should use f-string:
print(f"{name} result as {score}")
Sherine likes this post
Reply
#4
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Explanation of code ejKDE 4 371 Feb-26-2024, 02:50 PM
Last Post: ejKDE
  Unable to understand the meaning of the line of code. jahuja73 0 303 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Csv writer meaning of quoting mg24 2 1,136 Oct-01-2022, 02:16 PM
Last Post: Gribouillis
  A better explanation of the last post Led_Zeppelin 9 2,373 Sep-20-2022, 05:08 PM
Last Post: deanhystad
  meaning of -> syntax in function definition DrakeSoft 5 1,947 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Explanation of except ... as : Fernando_7obink 2 1,922 Feb-13-2021, 04:45 AM
Last Post: deanhystad
  .maketrans() - a piece of code which needs some explanation InputOutput007 5 2,955 Jan-28-2021, 05:05 PM
Last Post: buran
  .remove() from a list - request for explanation InputOutput007 3 2,213 Jan-28-2021, 04:21 PM
Last Post: InputOutput007
  parser.parse_args() meaning vinci 2 2,602 Oct-26-2020, 04:13 PM
Last Post: vinci
  Explanation of the left side of this statement please rascalsailor 3 2,494 Sep-09-2020, 02:02 PM
Last Post: rascalsailor

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020