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
  Difference and meaning in this scrips Udbytossen 4 923 Jun-29-2025, 03:41 PM
Last Post: Gribouillis
  Explanation of code ejKDE 4 2,096 Feb-26-2024, 02:50 PM
Last Post: ejKDE
  Unable to understand the meaning of the line of code. jahuja73 0 1,410 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Csv writer meaning of quoting mg24 2 2,671 Oct-01-2022, 02:16 PM
Last Post: Gribouillis
  A better explanation of the last post Led_Zeppelin 9 5,002 Sep-20-2022, 05:08 PM
Last Post: deanhystad
  meaning of -> syntax in function definition DrakeSoft 5 4,721 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Explanation of except ... as : Fernando_7obink 2 3,082 Feb-13-2021, 04:45 AM
Last Post: deanhystad
  .maketrans() - a piece of code which needs some explanation InputOutput007 5 5,080 Jan-28-2021, 05:05 PM
Last Post: buran
  .remove() from a list - request for explanation InputOutput007 3 3,539 Jan-28-2021, 04:21 PM
Last Post: InputOutput007
  parser.parse_args() meaning vinci 2 5,560 Oct-26-2020, 04:13 PM
Last Post: vinci

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.