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

Show several ways to print results

巴扎黑
Release: 2017-07-18 18:26:37
Original
1955 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template