Python-the difference between python2 and 3, comments, formatted output

1. The difference between python2 and python3

<1>
The syntax of python2 supports print ('hello world') and print 'hello world'
The syntax of python3 can support print ('hello world'), but it does not support print 'hello world'

As shown below:
Insert picture description here
<2>
python2 can not parse Chinese, its default encoding format is not utf-8, and python3 can parse Chinese.
Insert picture description here
If python2 can parse Chinese, you need to specify the encoding format as utf-8.
Insert picture description here
Now Python2 can parse Chinese format. Of course, the default format of python3 is utf-8, so it can also parse Chinese format.
Insert picture description here
<. 3> INPUT
python2 in input () is the only user input numbers, characters can not be
Insert picture description here
python2 need to input character with raw_input (), raw_input () value of any user input will be treated as a string are
Insert picture description here
python3 the All user input is replaced as a string, and it does not have raw_input ().
Insert picture description here

2. Notes

<1> The comment will not affect the operation of the program.
<2> Comment place: Generally simple sentences can be understood by others without comments, more than multiple lines of complex code, you need to comment at the beginning of the code, so that others can see what you want to do at a glance.
<3> Annotation methods are as follows:
Insert picture description here

3. Formatted output

In Python, we use the print statement to output. The output can be text or data. If text data is to be output at the same time, it needs to be formatted.
Placeholder:

%s Represents a string (str)
%d Integer (int)
%f Represents floating point type (float)
%% Indicates the percent sign (%)

Such as:
Insert picture description here

Published 41 original articles · praised 0 · visits 1698

Guess you like

Origin blog.csdn.net/qq_44749796/article/details/105586128