Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsiTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
In Python, % has different meanings depending on what surrounds it: between numbers it performs modulo arithmetic, while after a string format template it performs legacy string interpolation. In modern format strings, a percent format specifier instead scales a number by 100 and displays a percent sign. The operands and syntax—not the character alone—tell you which operation is happening.
What does % mean in Python?
Python uses the same symbol in several contexts. The main ones are numeric modulo, old-style string interpolation, and the percentage presentation type in modern string formatting.
| Context | Example | Meaning |
|---|---|---|
| Numeric expression | 17 % 5 |
Modulo: computes the result of the modulo operation. |
| String template on the left | 'Hello, %s' % 'Ada' |
Old-style interpolation: substitutes a value into the template. |
| Format specification | f'{0.25:.1%}' |
Displays a percentage, multiplying the value by 100 and adding %. |
The Python documentation describes the % operator on strings as both modulo and string formatting, reflecting these distinct contexts. Python built-in types documentation
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
How does % work as the modulo operator?
When the operands are numeric, % is the modulo operator. For example:
#1 Best Overall
remainder = 17 % 5
print(remainder) # 2
Modulo is commonly described as finding a remainder. For positive integers like these, 17 divided by 5 leaves 2. Python’s language reference specifies the exact behavior of arithmetic expressions, including cases where operands are negative; consult it when sign behavior matters. Python expressions reference
How does percent-style string formatting work?
If a string containing conversion markers is on the left of %, Python treats it as a formatting template. The right operand provides the value or values to substitute.
Rank #2
One value
name = 'Ada'
greeting = 'Hello, %s' % name
print(greeting) # Hello, Ada
Here, %s is a conversion specification, and the string on the right supplies its value. This is interpolation, not remainder arithmetic.
Free tools Windows power users keep installed
One-click scans. No signup required.
Multiple values
For multiple conversions, provide a tuple with corresponding values:
message = '%s has %d quote types.' % ('Python', 2)
print(message) # Python has 2 quote types.
The conversion markers and supplied arguments need to match. Tuple shape and argument counts can cause errors if they do not; percent-style formatting also supports mapping-based conversions, which use keys in the template.
Mapping values and a literal percent sign
language = '%(language)s' % {'language': 'Python'}
rate = 'Progress: 50%%' % ()
print(language) # Python
print(rate) # Progress: 50%
A keyed conversion such as %(language)s looks up a value in a mapping. In old-style formatting, write %% in the template to emit one literal percent sign; that conversion consumes no argument. Python built-in types documentation
How do you format a number as a percentage?
Use the % presentation type in a modern format specification. It multiplies the numeric value by 100 for display and appends a percent sign.
fraction = 0.25
print(f'{fraction:.1%}') # 25.0%
print('{:.0%}'.format(0.42)) # 42%
In {fraction:.1%}, .1 requests one digit after the decimal point and % selects percentage presentation. The value remains a fraction in your program; the formatting operation changes how it is displayed. Python string formatting documentation
Best Value
Which formatting style should you use?
| Style | Example | How values are supplied | When it fits |
|---|---|---|---|
| Percent-style interpolation | 'Hello, %s' % name |
Values follow the template, often in a tuple or mapping. | Maintaining existing code that already uses this style. |
| f-string | f'Hello, {name}' |
Expressions appear inside braces in the string. | Writing readable strings that include values or expressions. |
str.format() |
'Hello, {}'.format(name) |
Brace-delimited fields refer to positional or named values. | Formatting with brace fields, including cases where values are supplied separately. |
Python’s documentation presents f-strings and str.format() as alternatives to older percent-style formatting. It notes that newer interfaces may help avoid some quirks of percent formatting, whose supported types are narrower and whose argument handling can be harder to use correctly. Choose based on clarity and compatibility with the surrounding code rather than assuming one style is always faster. Python tutorial: input and output Python built-in types documentation
Quick Recap
How can you tell which meaning applies?
- If the expression has numeric operands around
%, read it as modulo. - If a string template is on the left and a value or tuple follows
%, read it as old-style interpolation. - If
%appears inside a modern format specification such as{:.1%}, it means percentage presentation. - If you need a literal percent sign in a percent-style template, use
%%.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

