{article Examples__Python 3.4 }{title} {text} {/article}
String Formatting Operator: %
One of Python's coolest features is the string format operator %
| Conversion | Meaning |
|---|---|
| %d | Signed integer decimal. |
| %i | Signed integer decimal. |
| %o | Signed octal value. |
| %u | Obsolete type – it is identical to 'd'. |
| %x | Signed hexadecimal (lowercase). |
| %X | Signed hexadecimal (uppercase). |
| %e | Floating point exponential format (lowercase). |
| %E | Floating point exponential format (uppercase). |
| %f | Floating point decimal format. |
| %F | Floating point decimal format. |
| %g | Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise. |
| %G | Floating point format. Uses uppercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise. |
| %c | Single character (accepts integer or single character string). |
| %r | String (converts any Python object using repr()). |
| %s | String (converts any Python object using str()). |
| % | No argument is converted, results in a '%' character in the result. |