% formatting
In Python you can format string in a variety of ways. Using the % symbol you can place string almost any where.
print('customer A bought %s Quantity of Goods at %s unit price' %(qty,price))
#Output
customer A bought 100 Quantity of Goods at 70 unit price
The conversion types are:
Conversion | Meaning | Notes |
---|---|---|
'd' | Signed integer decimal. | |
'i' | Signed integer decimal. | |
'o' | Signed octal value. | (1) |
'u' | Obsolete type – it is identical to 'd' . | (6) |
'x' | Signed hexadecimal (lowercase). | (2) |
'X' | Signed hexadecimal (uppercase). | (2) |
'e' | Floating point exponential format (lowercase). | (3) |
'E' | Floating point exponential format (uppercase). | (3) |
'f' | Floating point decimal format. | (3) |
'F' | Floating point decimal format. | (3) |
'g' | Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise. | (4) |
'G' | Floating point format. Uses uppercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise. | (4) |
'c' | Single character (accepts integer or single character string). | |
'r' | String (converts any Python object using repr() ). | (5) |
's' | String (converts any Python object using str() ). | (5) |
'a' | String (converts any Python object using ascii() ). | (5) |
'%' | No argument is converted, results in a '%' character in the result. |