How is string formatting done through the % operator in Python – Programming Code Examples
Python

How is string formatting done through the % operator in Python1 min read

Formatting output using String modulo operator(%)

The % operator can also be used for string formatting. It interprets the left argument much like a printf()-style format string to be applied to the right argument.

Example:




Output:


Python uses C-style string formatting to create new, formatted strings. 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”.

Example:

Output:

 

 

 

Leave a Comment