Chapter I basic knowledge
- achieve two-digit integer division: Use the command switch-qnew (? ); use a double slash.
- From The future Import Division performs normal division as the calculator.
- Exponentiation Operator: 2 * * 3 (8), with function instead of POW (2,3), built-in function
- Long integer type: At the end of the number plus L. eg:10000000000000l
- Get user input
Input ("hint message:") eg:x = Input ("x:"). The input is a valid Python expression
Raw_input ("hint message:"), put the user input as raw data into the string.
- Built-in function, Standard function--POW, ABS, round: Rounding the floating-point number to the nearest integer value.
- module, you need to import it into the Python extension feature with import.
Eg:import math can be used Math.floor (32.9) #向下取整 32.0, ceil () rounding up
Use INT () to cast to an integral type. Int (Math.floor (32.9)) # 32
Use the From math import sqrt to use functions directly, without requiring the module name as a prefix.
The function can be referenced by a variable, Eg:foo = math.sqrt foo (4) is the same as MATH.SQRT (4), the square root is computed, and the result is 2.0
SQRT (-4) error, cannot process imaginary numbers (end with j), requires import Cmath, uses Cmath.sqrt (-4)
- The program automatically ends, you can add Raw_input ("Press") at the end of the code
- Concatenation of strings, "hello." + "World"
string printing, str ("Hello,world") #转换为用户看到的字符串 Hello,world
Repr ("Hello,world") #以合法的python表达式形式表示 ' Hello,world '
This conversion is useful when printing includes a number variable.
- The long string "" or "' does not need to be escaped with a backslash.
Note: The normal character spans the line: the last character in a row is a backslash, then "\" is the newline escape character
- The original string begins with "R", which avoids the use of escape characters. Eg:print r "C:\nowhere"
- A Unicode string, stored as a 16-bit Unicode character, and normally stored in 8-bit ASCII code.
"Book Notes", "Basic Python Tutorial" chapter I Basic knowledge