Code style
Variables do not need to be declared, define type, use del + variable name to delete the variable
One line statement, without semicolons, indented with tab tab
Pass indicates an empty method body
Comments
Text output
- 2.7: print ' text '
- 3.x: Print (' text ')
- Default output line end return, print (b, end= ', ') modified
- Multiple variables are separated by commas, and spaces are added by default between variables
- Remove escape interpretation of a string you can add the letter r:print (R ' C:\name ') before the first quotation mark
- Formatted output print ('% (language) s has% (number) 03d quote types. '% {' language ': "Python", "Number": 2})
Get input
- Inputtext=raw_input (' hinttext hint: ') #v2.7
- Inputtext=input () #v3. x
- Convert string to Integer: Int (inputtext)
In interactive mode, the variable "_" represents the last output
String
Number
- The Division (/) return value is float, and if you want to get the same rounding as C or Java, use '//' instead
- The ' * * ' operator denotes ' secondary ', with precedence higher than symbol, e.g. -3**2=-9
Multivariate assignment: A, B = B, a+b #等价于a =b;b=a+b;