Home > Article > Backend Development > python numeric types
The following editor will bring you a brief discussion of digital types and processing tools in Python. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look
Number type tools in python
Python provides a lot of advanced numerical programming for more advanced work Support and objects, including complete tools for numeric types:
1. Integers and floating point types,
2. Complex numbers,
3. Fixed-precision decimal numbers,
4. Rational fractions,
5. Sets,
6. Boolean type
7. Infinite integer precision
8. Various digital built-in functions and modules.
Basic number types
Python provides two basic types: integers (positive integers, negative integers) and floating point numbers (Note: Numbers with decimal parts), where in python we can use integers in multiple bases. And integers can be used with infinite precision.
The integer is expressed in decimal number string writing, and the floating point number is represented by a decimal point or scientific notation e. In the python2 version, integers are also divided into general integers (32 bits) and long integers (infinite precision). Long integers end with l. With python3, integers have only one form, with infinite precision.
Of course, integers in Python also appear in binary (0bxxxxxxxx), octal (0oxxxxxxxx), and hexadecimal (0x xxxxxxxx) forms.
Conversion between decimal numbers and other bases:
s=16 print(bin(s)) print(oct(s)) print(hex(s)) 运行结果: 0b10000 0o20 0x10
print('{0:o},{1:x},{2:b}'.format(16,16,16)) print('%o,%x,%X'%(16,16,16)) 运行结果: 20,10,10000 20,10,10
Conversion of other bases into decimal:
a=int('0b10000',2) b=int('0o20',8) c=int('0x10',16) print(a) print(b) print(c) 运行结果: 16 16 16
print(eval('16')) print(eval('0b10000')) print(eval('0o20')) print(eval('0x10')) 运行结果: 16 16 16 16
python expression operator
The expression is Mathematical symbols and operation symbols are written. The following table shows python expression operators and procedures:
Operator | Description |
yield | Generator function sending protocol |
lambda args:expression | Generate anonymous function |
x if y else z | Ternary expression |
x or y | Logical OR (there is a short-circuit algorithm) |
x and y | Logical AND (there is a short-circuit algorithm) |
not x | Logical NOT |
x in y , x not in y | Member relationship |
x is y ,x is not y | Object entity test |
x9ed41611d0522aeaf6f0eb242c851d8cy,x>=y,x==y,x!=y | Compare sizes |
x|y | Bitwise OR, set union |
x^y | bit XOR, set symmetric difference |
bit and, set intersection | |
Shift left or right by y bits | ##x+y,x-y |
x*y,x%y,x/y,x//y | |
-x,+x | |
~x | |
x**y | |
x[i] | |
x[i:j:k] | |
x(...) | |
x.attr | |
(...) | |
[...] | |
{...} | |
The above is the detailed content of python numeric types. For more information, please follow other related articles on the PHP Chinese website!