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
  A better explanation of the last post Led_Zeppelin 9 844 Sep-20-2022, 05:08 PM
Last Post: deanhystad
  meaning of -> syntax in function definition DrakeSoft 5 685 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Explanation of except ... as : Fernando_7obink 2 1,258 Feb-13-2021, 04:45 AM
Last Post: deanhystad
  .maketrans() - a piece of code which needs some explanation InputOutput007 5 1,684 Jan-28-2021, 05:05 PM
Last Post: buran
  .remove() from a list - request for explanation InputOutput007 3 1,442 Jan-28-2021, 04:21 PM
Last Post: InputOutput007
  parser.parse_args() meaning vinci 2 1,456 Oct-26-2020, 04:13 PM
Last Post: vinci
  Explanation of the left side of this statement please rascalsailor 3 1,608 Sep-09-2020, 02:02 PM
Last Post: rascalsailor
  What is the meaning of k in this function? giladal 3 1,664 Aug-15-2020, 12:32 PM
Last Post: buran
  Here what is the meaning of span=(1,2) ,match='1'? srisrinu 1 1,340 Apr-27-2020, 10:22 AM
Last Post: anbu23
  What is the meaning of mutable data type? qliu 3 1,810 Apr-17-2020, 07:20 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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