It is a string formatting syntax (which it borrows from C).

Please see "PyFormat":

Python supports formatting values into strings. Although this can include very complicated expressions, the most basic usage is to insert values into a string with the %s placeholder.

Here is a really simple example:

#Python 2
name = raw_input("who are you? ")
print "hello %s" % (name,)

#Python 3+
name = input("who are you? ")
print("hello %s" % (name,))

The %s token allows me to insert (and potentially format) a string. Notice that the %s token is replaced by whatever I pass to the string after the % symbol. Notice also that I am using a tuple here as well (when you only have one string using a tuple is optional) to illustrate that multiple strings can be inserted and formatted in one statement.

Answer from Andrew Hare on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › what-does-s-mean-in-a-python-format-string
What does %s mean in a Python format string? - GeeksforGeeks
July 23, 2025 - In Python, the %s format specifier is used to represent a placeholder for a string in a string formatting operation. It allows us to insert values dynamically into a string, making our code more flexible and readable.
Discussions

What does %d and %s do in Python and why do we use it?
Python f string formatting has largely replaced the need for either the % formatting or the "{}" .format() approach, I recommend you learn that! More on reddit.com
🌐 r/learnpython
31
50
August 18, 2024
file - What does %s" % stand for in a Python print statement - Stack Overflow
This should answer your question: What's the difference between %s and %d in Python string formatting? ... Save this answer. ... Show activity on this post. % means parameter passed into the string. %s is parameter that should be treated as string There are some other kinds of parameters types ... More on stackoverflow.com
🌐 stackoverflow.com
What does %s mean in Python?

It allows you to print a string in a string. So if you wanted to customize a "Hello Word" with a name you could do name = raw_input("Name?") print "Hello %s" % name

More on reddit.com
🌐 r/learnprogramming
5
4
August 15, 2015
What does %d and %s do in Python and why do we use it?
What should you actually learn in Python before starting data analysis? ... I’ve noticed that beginners often get stuck trying to learn all of Python before touching data analysis. From what I’ve seen, you can get pretty far by focusing on a smaller set of concepts: One thing I think is ... More on reddit.com
🌐 r/learnpython
🌐
Career Karma
careerkarma.com › blog › python › what does %s mean in python?
What Does %s Mean in Python?: A Complete Guide | Career Karma
December 1, 2023 - Do you want to add a value into a Python string? You need not look further than the %s operator. This operator lets you format a value inside a string. The %s syntax is more elegant than the concatenation operator with which you may be familiar.
🌐
Quora
quora.com › What-does-s-mean-in-python
What does '%s' mean in python? - Quora
Answer (1 of 17): In python, there are many ways to print a statement. One way of doing this is by uaing format specifiers. Format specifiers are special argumments that specify the format of input that has to be taken by the user and the format that has to be given to the user. %s is a format...
🌐
Codingem
codingem.com › home › python string %s — what does it mean? (with examples)
Python String %s — What Does It Mean? (with Examples)
October 25, 2022 - Python string with %s is an old string formatting technique. The %s is placed into a string and it acts as a placeholder for another string variable.
🌐
AskPython
askpython.com › python › string › python-format-string-string-placeholder
What Does %s Mean in a Python Format String? - AskPython
April 23, 2023 - Usually, when you try to print something using the built-in print function available in Python, you will have to do a lot of type conversions as the print function takes only one type of a variable at a time. That is, if you are printing a string and an integer in the same line, you will have to convert the integer into a string or we can separate it using commas.
Find elsewhere
🌐
W3docs
w3docs.com › python
What does %s mean in a Python format string? | W3Docs
In a Python format string, the %s placeholder represents a string. It is used to indicate that a string should be inserted at that position in the final string.
🌐
Reddit
reddit.com › r/learnpython › what does %d and %s do in python and why do we use it?
r/learnpython on Reddit: What does %d and %s do in Python and why do we use it?
August 18, 2024 -

Hello, so I am starting to learn python on my own learnpython.org and I am currently on the string formatting section and it starts talking about %d and $s. I kinda understand what it does but not really. However my main question is why do we use %s and %d. One example I have seen was

name = 'Geek

print ("Hey, %s,!" % name)

This printed out "Hey, Geek!". But why do we use it when we can also just do

print ("Hey", name)

As I am typing this out I kind of see the use but still any advice would be helpful

Edit: Thanks for all the replies they really helped!! I will be sending in thousands of more questions as I continue to learn.

Top answer
1 of 7
103
Python f string formatting has largely replaced the need for either the % formatting or the "{}" .format() approach, I recommend you learn that!
2 of 7
23
There are multiple ways to insert a variable into a string and format it. The mod % operator allows insertion of variables from a tuple. base = 'Hello %s%s My favourite number is %d.' variables = ('World', '!', 4) base % variables This returns: 'Hello World! My favourite number is 4.' The s indicates that a string is to be inserted and the d indicates that a decimal integer is to be inserted. The course you are following must be pretty old as there have been newer ways to format strings which are recommended over use fo the % operator. These revolve around the format method: base = 'Hello {0}{1} My favourite number is {2}' variables = ('World', '!', 4) base.format(*variables) This returns: 'Hello World! My favourite number is 4.' Most Python IDEs will apply syntax highlighting (Reddit doesn't unfortunately) which makes it clear that a variable is posiitonally being inserted into the braces. In this case the numeric values relate to the index of the tuple. It is more common to use named parameters: base = 'Hello {who}{exclaim} My favourite number is {num}.' variables = (who='World', exclaim='!', num=4) base.format(*variables) This returns: 'Hello World! My favourite number is 4.' The * means you are unpacking the tuple removing the parenthesis, essentially supplying who='World', exclaim='!', num=4 to the function instead of (who='World', exclaim='!', num=4) Now when you have the variables defined as: who = 'World' exclaim = '!' num = 4 base = 'Hello {who}{exclaim} My favourite number is {num}.' variables = dict(who=who, exclaim=exclaim, num=num) base.format(**variables) The ** means you are unpacking the dictionary, removing the dict() enclosing dict(who=who, exclaim=exclaim, num=num) giving who=who, exclaim=exclaim, num=num. Notice the last three lines can be combined: 'Hello {who}{exclaim} My favourite number is {num}.'.format(who=who, exclaim=exclaim, num=num) However it becomes tedious to mention each variable 3 times... so this can be abbreviated using the prefix f: f'Hello {who}{exclaim} My favourite number is {num}.' In the {} you can insert the variable, but you can also use a colon to include a format specifier. For example: f'Hello {who:s}{exclaim:s} My favourite number is {num:d}.' You can set the width of each variable: f'Hello {who:10s}{exclaim:10s} My favourite number is {num:10d}.' 'Hello World ! My favourite number is 4.' If you want to see the leading zeros for the number you can add the 0 prefix: f'Hello {who:10s}{exclaim:10s} My favourite number is {num:010d}.' 'Hello World ! My favourite number is 0000000004.' There is a string format specification minilanguage. For more details see the Python Documentation: string Miniformat Language . Most of the format specification is for inserting numbers into a string specifically a floating point format. It is easier to see whats happening by looking at the examples at the bottom of the page. Using f will five the fixed format for example 0.1234 (this has a width of 6 characters, a precision of 4 characters after the decimal point so can be 6.4f). Using e will give the exponent format 1.234e-1 for example (this has a width of 8 characters and a precision of 3 characters so can be 6.3e). I cover some common use cases in this video YouTube Spyder IDE: Numeric Values (20 mins in)
🌐
Stack Abuse
stackabuse.com › the-difference-between-s-and-d-in-python-string-formatting
The Difference Between %s and %d in Python String Formatting
July 2, 2023 - Two of the most common format specifiers used with the % operator are %s and %d. The %s format specifier is a placeholder for a string. The %s specifier converts the object using str(), which means it doesn't necessarily need to be a string. It can be any Python object, such as a number or ...
🌐
freeCodeCamp
freecodecamp.org › news › python-string-format-python-s-print-format-example
Python String Format – Python S Print Format Example
September 7, 2021 - One of the older ways to format strings in Python was to use the % operator. ... You can create strings and use %s inside that string which acts like a placeholder. Then you can write % followed be the actual string value you want to use.
🌐
JanBask Training
janbasktraining.com › community › python-python › what-does-s-mean-in-a-python-format-string
What does %s mean in a python format string? | JanBask Training Community
April 14, 2021 - If you are searching for an answer of “what does %s mean in python” Kindly be informed that the % is a string formatting syntax in Python.
🌐
Learn Python
learnpython.org › en › String_Formatting
String Formatting - Learn Python - Free Interactive Python Tutorial
The "%" operator is used to format a set of variables enclosed in a "tuple" (a fixed size list), together with a format string, which contains normal text together with "argument specifiers", special symbols like "%s" and "%d".
🌐
GeeksforGeeks
geeksforgeeks.org › python › difference-between-s-and-d-in-python-string
Difference between %s and %d in Python string - GeeksforGeeks
July 23, 2025 - The %s operator is put where the string is to be specified. The number of values you want to append to a string should be equivalent to the number specified in parentheses after the % operator at the end of the string value.
🌐
Stack Overflow
stackoverflow.com › questions › 68898228 › what-does-s-stand-for-in-a-python-print-statement
file - What does %s" % stand for in a Python print statement - Stack Overflow
The %s is a placeholder for strings using the old formatting methods in python. Essentially %s gets replaced by the string value of my_int in your example.
🌐
Udacity
udacity.com › blog › 2020 › 11 › python-string-format-whats-the-difference-between-s-and-d.html
Python String Format: What's the Difference Between %s and %d? | Udacity
October 24, 2024 - Of the three types, you’ll almost always use %d for casting numbers as strings in Python string formatting. The technical difference between %s and %d is simply that %d calls int() on the argument before calling str().
🌐
Wikitechy
wikitechy.com › string-s-python-print-format-example
String S Python: Master Python’s %s Format Easily
November 5, 2025 - To use string s Python, you write your string with placeholders (%s), and then use the % operator to pass in values. ... The flexibility of string s Python is what makes it timeless.
🌐
Python Pool
pythonpool.com › home › tutorials › python %s formatting: placeholders, tuples, and safer alternatives
Python %s Formatting: Placeholders, Tuples, and Safer Alternatives
July 13, 2026 - Use one %s placeholder when one value should be inserted into a string. Python converts the value with str(). name = "Maya" message = "Hello, %s!" % name print(message) The % operator is part of the expression.
🌐
Zack's Ad hoc Page
zhihuicao.wordpress.com › 2015 › 06 › 29 › what-does-s-mean-in-python
What does %s mean in Python? – Zack's Ad hoc Page
February 16, 2016 - The %s token allows me to insert (and potentially format) a string. Notice that the %s token is replaced by whatever I pass to the string after the % symbol.