-4
\$\begingroup\$

I'm not sure what %s means in Python strings. I came across this line of code somewhere a while ago: print("On your journey to %s, you drove at an average speed of %s miles per hour." % (where, speed)) and I just came across a question with the following line: print("The", count, "prime number is %s" %index). And how come neither of the above examples had to use + to combine the strings and integers (presumably) and how come they didn't use str to covert the integers (again presumably...could be floats) to string format?? I am SO confused...

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to Code Review! Unfortunately this question is off-topic because this site is for reviewing working code. Please take the tour and read up at our help center. When you have working code then feel free to edit the post to include it for a review. \$\endgroup\$ Dec 2, 2020 at 23:40
  • \$\begingroup\$ @SᴀᴍOnᴇᴌᴀ Sorry about that. But thanks for the heads-up. \$\endgroup\$ Dec 2, 2020 at 23:42

1 Answer 1

-1
\$\begingroup\$

As already said, this question is off-topic but it's not a stupid question, so don't get discouraged. This question isn't applicable to this platform as it is not an issue you're having with your code. If you could provide your code and then ask what %s means, it would make more sense, as I can see what you are trying to do (and if you're using %s correctly).

But for clarity's sake, %s in Python is really just used for inserting and possibly formatting a string (it saves time with casting and concatenating; two very important terms!).

The following links may provide more helpful and thorough insights into %s:

Keep in mind: this platform is for reviewing and sorting problems for code. No surprises, as the first section of the link is "codereview.stackexchange.com"

\$\endgroup\$
2
  • \$\begingroup\$ Thank you for your time. I will make sure to look over the website in order to fully understand the meaning of %s. \$\endgroup\$ Dec 3, 2020 at 0:04
  • \$\begingroup\$ @pgrm_geek If you need help with non-working code or if you have questions, stack overflow is good. However, you should be warned that people are a lot meaner over there. \$\endgroup\$
    – fartgeek
    Dec 3, 2020 at 1:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.