Home >Backend Development >Python Tutorial >Show several ways to print results

Show several ways to print results

巴扎黑
巴扎黑Original
2017-07-18 18:26:371937browse

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

Show several ways to print results

         Show several ways to print results

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn