Built-in data types
Python's built-in data types range from scalars like numeric and boolean to more complex structures like lists, dictionaries, and files.
numerical value
Python has 4 numeric types i.e. Integer, Floating Point, Complex and Boolean.
Floating point -- 3.0, 31e12, -6e-4. Complex numbers -- 3 + 2j, -4- 2j, 4.2 + 6.3j. Boolean -- True, False. --Numeric types perform arithmetic operations with arithmetic operators, including + (addition), - (subtraction), * (multiplication), / (division), ** (power), and % (modulus).
The following is an example of the use of the integer type:
>>> x = 5 + 2 - 3 * 2 >>> x 1 > >> 5 / 2 2.5 ⇽--- ❶ >>> 5 // 2 2 ⇽--- ❷ >>> 5 % 2 1 >>> 2 ** 8 256 >>> 1000000001 ** 3 1000000003000000003000000001 ⇽--- ❸
Dividing an integer with "/"❶ will result in a floating point number (this is a new rule in Python). Dividing an integer with "//"❷ truncates the result to an integer. Note that there is no limit to the size of an integer ❸ it grows automatically as needed, limited only by the amount of memory available.
The following is an example of the operation of the floating-point type, which is based on the double-precision data type implementation of the C language: '
>>> x = 4.3 ** 2.4 >>> x 33.13784737771648 >>> 3.5e30 * 2.77e45 9.695e+75 >>> 1000000001.0 ** 3 1.000000003e+27
Here is an example of the plural type:
>>> (3+2j) ** (2+3j) (0.6817665190890336-2.1207457766159625j) >>> x = (3+2j) * (4+9j) >>> x ⇽--- ❶ (-6+35j) >>> -6.0 >>> 35.0
A complex number consists of a combination of real and imaginary parts with a suffix j. In the above code, the variable x is assigned a complex number ❶. Here the real part is obtained by using attributes and the imaginary part by using then.
There are a number of built-in functions for manipulating numeric types, and Python provides the library modules cmath (which contains functions for working with complex numbers) and math (which contains functions for working with the other three numeric types).
>>> round(3.49) ⇽--- ❶ 3 >>> import math >>> (3.49) ⇽--- ❷ 4
The built-in functions are always available and are called using standard function call syntax. In the above code, the round function is called with a floating point number as the input parameter ❶.
Functions in library modules can only be used after they have been imported using the import statement. At ❷, after importing the library module math, the ceil functions are called with the attribute syntax: (arguments).
The following is an example of Boolean operation:
>>> x = False >>> x False >>> not x True >>> y = True * 2 ⇽--- ❶ >>> y 2
Booleans behave similarly to the values 1 (True) and 0 (False), except that they are represented by True and False ❶.
This is all about the numerical basics in python, thanks for learning and supporting me.