Home >Backend Development >Python Tutorial >Show several ways to print results
1, str() and repr()
The purpose of str() is readability, and the purpose of repr() is to make the results clear and unambiguous
There is not much difference between the two
2, it is recommended to use the format of the following. Format () format printing:
Print ('A is {} and b is {}'. Format ('a', 'b')))
3, you can use digital control output positions in large brackets:
PRINT ('A IS {1} and b is {0}'. Format ('a', 'B', 'B' ))
4, output format control, use '!a' for ascii(), '!s' for str(), and '!r' for repr():
import math
print ('The value of PI is {!r}'.format(math.pi))
5, use ':' to control the output format more effectively
The above is the detailed content of Show several ways to print results. For more information, please follow other related articles on the PHP Chinese website!