In python you can specify the format inside the curved brackets.

You can do things such as

>>> '{:b}'.format(2)
'10'

In your case, d prints as decimal integer.

You can find all the doc here

https://docs.python.org/2/library/string.html#format-specification-mini-language

Answer from BlueSheepToken on Stack Overflow
🌐
Python
python.org › downloads
Download Python | Python.org
Python 3.13.12 Feb. 3, 2026 Download Release notes
🌐
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)

In python you can specify the format inside the curved brackets.

You can do things such as

>>> '{:b}'.format(2)
'10'

In your case, d prints as decimal integer.

You can find all the doc here

https://docs.python.org/2/library/string.html#format-specification-mini-language

Answer from BlueSheepToken on Stack Overflow
🌐
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 %d operator is used as a placeholder to specify integer values, decimals, or numbers. It allows us to print numbers within strings or other values. The %d operator is put where the integer is to be specified.
🌐
Python
python.org
Welcome to Python.org
Python is a programming language that lets you work quickly and integrate systems more effectively. Learn More · Whether you're new to programming or an experienced developer, it's easy to learn and use Python.
🌐
Udacity
udacity.com › blog › python-string-format-whats-the-difference-between-s-and-d
Python String Format: What's the Difference Between %s and %d? | Udacity
October 24, 2024 - These components allow for finer control over the display of certain conversion types, but remain optional. Only the modulo symbol and the conversion type are required. While elaborations on many different conversion types may be found in this Real Python tutorial, we’ll focus exclusively on two popular conversion types: %s and %d.
Find elsewhere
🌐
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 - In Python, the % operator is used for string formatting. It interprets the left argument much like a printf-style format string to be applied to the right argument, allowing you to format strings in a variety of ways. Two of the most common format specifiers used with the % operator are %s and %d.
Author: dlab-berkeley
🌐
Facebook
facebook.com › groups › 615958866343368 › posts › 840135883925664
please what does %d mean in python
Popular groups · Find communities for you · Over 1 billion people across the globe are using Facebook Groups to explore their favorite topics · Log in · Categories · Science & tech · Travel · Animals · Sports & fitness · Entertainment
🌐
Wikipedia
en.wikipedia.org › wiki › Python_(programming_language)
Python (programming language) - Wikipedia
2 weeks ago - Python is a high-level, general-purpose ... ("batteries-included") standard library, and garbage collection. Python supports multiple programming paradigms but with an emphasis on object-oriented programming and dynamic typing....
🌐
Wikipedia
en.wikipedia.org › wiki › Zen_of_Python
Zen of Python - Wikipedia
March 11, 2026 - An idea or piece of code which closely follows the most common idioms of the Python language, rather than implementing code using concepts common to other languages. For example, a common idiom in Python is to loop over all elements of an iterable using a for statement. Many other languages don’t ...
🌐
Google Play
play.google.com › store › apps › details
Pydroid 3 - IDE for Python 3 - Apps on Google Play
Features: - Offline Python 3 interpreter: no Internet is required to run Python programs. - Pip package manager and a custom repository for prebuilt wheel packages for enhanced scientific libraries, such as numpy, scipy, matplotlib, scikit-learn and jupyter. - OpenCV is now available (on devices with Camera2 API support).
Rating: 4.4 ​ - ​ 89.4K votes
🌐
W3Schools
w3schools.com › python › python_string_formatting.asp
Python String Formatting
A modifier is included by adding a colon : followed by a legal formatting type, like .2f which means fixed point number with 2 decimals: ... You can perform Python operations inside the placeholders.
🌐
Quora
quora.com › What-are-the-differences-among-s-r-and-d-in-Python
What are the differences among %s, %r and %d in Python? - Quora
Answer (1 of 5): From the python documentation, %s : String (converts any Python object using str()). %r : String (converts any Python object using repr()). %d : Signed integer decimal. For the technical differences between %s and %r check out this answer on stackover flow : Page on stackoverfl...
🌐
Posit
posit.co
Posit | Data Science Platform for Enterprise Teams
Move from question to insight to analysis, model or application faster than ever before. Positron is the free code editor made specifically for data science and analysis with Python and R.
🌐
D Programming Language Discussion Forum
forum.dlang.org › thread › uptzeozozquzhnozuosv@forum.dlang.org
Using python in D - D Programming Language Discussion Forum
June 7, 2019 - Duyuru · Log in · Settings · Help · Index » Learn » Using python in D · Top | Forum index | About this forum ·