Python print statement
The print statement can output the specified text to the screen. For example, output ‘hello, world’, using code to achieve the following:
>>> print 'hello, world'
1. When we write code in a Python interactive environment, it
>>>is the prompt of the Python interpreter, not part of the code.
2. When we write code in a text editor, do n’t add >>> yourself .
The print statement can also be followed by multiple strings, separated by a comma “,” to join a series of output:
>>> print 'The quick brown fox', 'jumps over', 'the lazy dog' The quick brown fox jumps over the lazy dog
Print prints each string in turn, and a comma “,” will output a space, 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 computing 100 + 200 more beautifully:
>>> print '100 + 200 =', 100 + 200 100 + 200 = 300 #Run results
Note: For 100 + 200, the Python interpreter automatically calculates the result 300, but ‘100 + 200 = ‘ is a string rather than a mathematical formula, and Python treats it as a string. Please explain the above print results yourself.