Python's print statement Python's comments

Without further ado, let's get straight to the point

The print statement prints the specified text to the screen. For example, to output 'hello, world', the code is implemented as follows:
>>> print 'hello, world'

Notice:

1. When we write code in the Python interactive environment, >>> is the prompt of the Python interpreter, not part of the code.

2. When we write code in a text editor, don't add it by yourself >>>

The print statement can also follow multiple strings, separated by commas "," to form a string of output:
>>> print 'The quick brown fox', 'jumps over', 'the lazy dog'
The quick brown fox jumps over the lazy dog
print will print each string in turn, and a space will be output when a comma "," is encountered, so the output string is spelled like this
print can also print integers, or calculate the result:
>>> print 300 300 #run result
>>> print 100 + 200 300 #run result
Therefore, we can print the result of calculating 100 + 200 a little more beautifully:
>>> print '100 + 200 =', 100 + 200
100 + 200 = 300 #running result
Note: For 100 + 200, the Python interpreter automatically calculates the result of 300. However, '100 + 200 =' is a string rather than a mathematical formula, and Python treats it as a string. Please interpret the above printed result by yourself.

At any time, we can add comments to the program. Comments are used to explain the code and show it to yourself or others. When the program is running, the Python interpreter will ignore the comments directly. Therefore, whether there are comments does not affect the execution result of the program, but affects whether others can understand you. code.
Python comments start with  #  , and the following text is considered a comment until the end of the line
# This line is all comments...
print 'hello' # This is also a comment
There is also a clever use of comments, that is, some code we do not want to run, but do not want to delete, we can temporarily block it with comments:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325097645&siteId=291194637