Python number type: 1. Integer type, usually called an integer or integer, can be a positive or negative integer without a decimal point; 2. The floating point type consists of an integer part and a decimal part; 3 , Boolean type; 4. Complex numbers are composed of real parts and imaginary parts.
Related free learning recommendations:python video tutorial
Python number type:
①Integer type:
is usually called an integer or integer, which can be positive An integer or negative integer without a decimal point. Python3 integers have no size limit and can be used as long types. However, in fact, due to the limited machine memory, the integers we use cannot be infinitely large.
Four expressions of integer:
2 base: starting with '0b'. For example: '0b11011' represents 27
in decimal. Octal: starts with '0o'. For example: '0o33' means 27 in decimal system
Decimal system: normal display
Hexadecimal system: starts with '0x' . For example: '0x1b' means 27 in decimal system
Conversion between numbers (built-in function):
bin(i) : Convert i to binary, starting with "0b".
oct(i): Convert i to octal, starting with "0o".
int(i): Convert i to decimal and display normally.
hex(i): Convert i to hexadecimal, starting with "0x".
②Floating point number:
The floating point type consists of an integer part and a decimal part. The floating point type can also use scientific notation. French representation (2.5e2 = 2.5 x 102 = 250)
③Boolean type:
All standard objects can be used for Boolean testing, and objects of the same type can Comparison of size. Every object is born with a Boolean True or False value. An empty object, any number with a value of zero, or a Null object with a Boolean value of None is False. In Python3, True=1, False=0, and can be operated with numeric types.
The Boolean value of the following objects is False:
None; False; 0 (integer), 0.0 (floating point); 0L (long integer); 0.0 0.0j (complex number); "" (empty string); [] (empty list); () (empty tuple); {} (empty dictionary).
The Boolean value of an object whose value is not any of the values listed above is True, such as non-empty, non-zero, etc. If user-created class instances define nonzero(_nonzeor_()) or length(_len_()) and the value is 0, then their Boolean value is False.
④Complex numbers:
A complex number consists of a real part and an imaginary part. It can be represented by a bj, or complex(a,b). The real part of the complex number is a and The imaginary part b is all floating point type.
The above is the detailed content of What are the python number types?. For more information, please follow other related articles on the PHP Chinese website!