Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Python provides three basic types of numbers.
Python provides three basic types of numbers.
1, integer

Usually called integer or integer, it can be a positive integer or a negative integer without decimal point. Python3 integer has no size limit and can be used as a long type, but in fact, due to the limited memory of the machine, the integer we use cannot be infinite.

Four manifestations of integers:

Binary: starts with "0b". For example,' 0b1101'means 27 in10.

Octal: starts with "0o". For example, "0o33" means 65438+27 based on 00.

Decimal: Normal display

Hexadecimal: starts with "0x", for example, "0x 1b" means 27 in 10.

Convert the number between each entry:

Bin(i): Convert I to binary, starting with' 0b'.

Oct(i): Convert I to octal, starting with' 0o'.

Int(i): Convert I to 10, and display normally.

Hex(i): Convert I to 16, starting with "0x".

2. Floating point number

Floating-point type consists of integer part and decimal part, and floating-point type can also be expressed by scientific counting method, such as: 2.5e2 = 2.5 x 102 = 250.

3. Boolean type

All standard objects can be used for Boolean testing, and objects of the same type can be compared in size. Every object is born with a true or false Boolean value. An empty object, any number with a value of zero, or the Boolean value None of a Null object is False. In python3, True= 1 and False=0, which can be operated by numbers.

The Boolean values of the following objects are false:

None; Fake; 0 (integer), 0.0 (floating point); 0L (long shaping); 0.0+0.0j (complex number); (empty string); [] (empty list); () (empty tuple); {} (empty dictionary).

Boolean values of objects whose values are not any of the above values are true, such as non-null, non-zero, etc. User-created class instances are defined by nonzero (_nonzeor_ ()) or length (_len_ ()), and their Boolean values are False.

4. Complex number

Complex number consists of real part and imaginary part, which can be expressed by a+bj or complex number (a, b). The real part A and imaginary part B of a complex number are both floating-point types.