Integer
- Definition: a = 125.
- Python can handle integers of "arbitrary" size including negative numbers.
- Support binary, octal, decimal, hexadecimal
Distinguish by prefix:
Prefix | example | Base |
0b or 0B | a = 0b1010 | 2 |
0o or 0O | a = 0o12 | 8 |
no | a = 10 | 10 |
0x or 0X | a = 0xa | 16 |
Floating point
Three methods defined:
- a = 1.2
- b = .4
- c = 1.2e-4
type()
We can use the type() function to determine which type the variable is
Numerical addition, subtraction, multiplication and division operations
When the division operation is performed by the / operator, the result of the division must be a floating point number regardless of whether it is divided or not
When an integer is divided by the // operator, the result must be an integer regardless of whether it is divisible or not
The result of adding and subtracting a multiplier of a floating-point number must be a floating-point number
String
definition:
- a = 'test'
- a = "test"
- a = "Chinese"
- a =''' contains a double quotation mark (") and a single quotation mark (')''' in a string (you can also add \ escape)
Calculate the length of the string len()
Addition and multiplication of strings
String formatting
The last method requires Python 3.6 or later to be supported.
Boolean
NONE
A null value is no value, not an empty value
a ='' is not called empty, a = None is called empty