Free tools Windows power users keep installed
One-click scans. No signup required.
In Python, % has different meanings in different contexts: with numeric operands it performs modulo arithmetic, while after a string format template it performs legacy string interpolation. In modern formatting, a percent format specifier such as {:.1%} scales a number by 100 and displays a percent sign.
What does % mean in Python?
Look at the expression around the symbol to identify its job. In a numeric expression such as 17 % 5, it is the modulo operator. In 'Hello, %s' % name, the left-hand string is a template and % inserts a value into it. In a format specification such as {:.1%}, it is a presentation type that formats a number as a percentage.
As an Amazon Associate I earn from qualifying purchases.
These uses share a character, not an operation. Python’s documentation describes percent-style string formatting as both a modulo operator and a string interpolation operator; the operands and syntax establish which meaning applies. See the Python built-in types documentation.
How does % work as modulo?
With numeric operands, % calculates the modulo result: remainder = 17 % 5 assigns 2 to remainder. This is useful for tasks such as checking whether a number is divisible by another number: n % 2 == 0 is true when n is even.
#1 Best Overall
Modulo is related to, but distinct from, floor division, written //. For ordinary positive integers, a // b gives the floor-divided quotient and a % b gives the corresponding remainder; for example, 17 // 5 is 3 and 17 % 5 is 2. Python’s expression reference defines the operators and their behavior, including cases involving negative values: Python expressions.
How does % format strings?
When the left operand is a string containing conversion markers, % performs old-style string interpolation. The markers specify how values are inserted; the value or values appear on the right.
Rank #2
Insert one or more values
name = 'Ada'
greeting = 'Hello, %s' % name
message = '%s has %d quote types.' % ('Python', 2)
%s is a string conversion marker and %d is an integer conversion marker. With multiple conversions, pass a tuple whose values correspond to the markers in order.
Use named values
label = '%(language)s' % {'language': 'Python'}
Mapping-based formatting uses a key in the conversion marker and a mapping, such as a dictionary, on the right. Argument shape matters: a tuple or mapping is interpreted according to the conversion markers, so mismatches can produce errors.
Include a literal percent sign
In old-style formatting, write %% in the template to emit a literal %. This conversion consumes no value, as documented in Python’s printf-style string formatting reference.
How do I format a number as a percentage?
Use the percent presentation type in a modern format specification. It multiplies the value by 100 for display and appends a percent sign:
f'{0.25:.1%}'
This produces 25.0%. The precision before the percent type controls decimal places: {:.0%} formats 0.42 as 42%. The same mini-language works with str.format():
Recommended Free Tools
'{:.1%}'.format(0.25)
Python documents the percent format type in Common string operations. It is formatting syntax, not modulo arithmetic.
Best Value
Which formatting style should you use?
| Style | Example | How values are supplied | Typical use |
|---|---|---|---|
Old-style % |
'Hello, %s' % name |
After the string, as a value, tuple, or mapping | Reading or maintaining existing code that uses percent conversions |
| f-string | f'Hello, {name}' |
Expressions appear inside braces in the string | Embedding values directly in a string |
str.format() |
'Hello, {}'.format(name) |
Arguments are passed to format(); fields can be positional or named |
Brace-based formatting when an f-string is not the chosen interface |
Python’s tutorial covers f-strings and other output-formatting approaches. The documentation notes that percent-style formatting supports a narrower range of types and can be harder to use correctly; newer interfaces can avoid some of its quirks. Choose based on the codebase and clarity rather than assuming one style is universally faster.
Quick Recap
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.




