Adding the From __FUTURE__ Import division to the Python program or executing it directly in the interpreter, or using the command switch-qnew when running python from the command line, will make the single slash no longer divisible, as
>>> 1/2
0.5
And a double slash is divisible, such as
>>> 1//2
0
>>> x = input (' x: ')
Import the module with import and use the function of the module in the format "module. function", as
>>> Import Math
>>> Math.floor (23.96)
23.0
After using the import command of the Form module import function, you can use the function directly, without requiring the module name as a prefix, as
>>> from math import sqrt
>>> sqrt (9)
3.0
The Cmath module enables processing of complex numbers such as
>>> Cmath.sqrt (-9)
3j
In idle, the file->new file pops up an edit window, which is edited as follows
Name = Raw_input ("what isyour name")print'Hello, ' ' ! '
Then File-save is saved as hell.py and then F5 runs, the result appears in the interpreter, such as
>>> ================================ RESTART ================================
>>>
What is your Name55
hello,55!
or double-click the hell.py, the command-line window flashes and dies.
In the code, #右边的一切都会被忽略, that part is the comment.
Anti-quotes, str, and repr are three ways to convert a value to a string, where STR converts the value into a reasonably-form string for the user to understand, and repr creates a string that represents the value in the form of a legitimate flat python expression, such as
TMP = +print ' + ' tmp 'print' + str (TMP)print' + repr (TMP)
The results are as follows
Hello 1000
Hello 1000
Hello 1000
Input assumes that the user entered a valid Python expression (more or less the opposite of the repr function), raw_input all the input as the raw data and then puts it into a string, such as
Print ' ' + raw_input ('your name:')print' ' + input ('your name:')
The results are as follows
Your name:55
Hello 55
Your name:55
Traceback (most recent):
File "e:/work/code/python/hell.py", line 2, <module>
print ' Hello ' + input (' Your name: ')
Typeerror:cannot concatenate ' str ' and ' int ' objects
If you want to write a long string that spans multiple lines, you can use three quotation marks instead of ordinary quotes, such as
Print " " This is a long string.it continues here.and It's not over yet. " Hello world! ". Still here. " "
The results are as follows
This is a long string.
It continues here.
And it ' s not over yet.
"Hello world!".
Ordinary strings can also span rows, and if the last character in a row is a backslash, the line break itself is "escaped", which is ignored (for expressions), as
Print ' This was a long string.it stop here. '
Results
This was a long string.it stop here.
The original string is not a backslash. As a special character, each character entered in a string is consistent with the way it is written, such as
print r'E:\work\Code\python'\ \'
The results are as follows
E:\work\Code\python\
Basic knowledge of the basic Python tutorial notes