Python Number(number)

The Python Number data type is used to store numeric values.

The data type is not allowed to change, which means that if you change the value of the Number data type, the memory space will be reassigned.

The following instance will be created when the variable is assigned:

var1 = 1
Var2 = 10

You can also delete some Number object references using the del statement.

The syntax of the

del statement is:

del var1[,var2[,var3[....,varN]]]]

You can delete single or multiple objects by using the del statement, for example:

del var
del var_a, var_b

Python supports four different numeric types:

  • Int - Usually referred to as an integer or integer, is a positive or negative integer without a decimal point.
  • long integers - an integer of infinite size, the integer being an uppercase or lowercase L.
  • floating point real values - The floating point type consists of an integer part and a fractional part, and the floating point type can also be represented by scientific notation (2.5e2 = 2.5 x 102 = 250)
  • complex numbers - The complex number consists of a real part and an imaginary part, which can be represented by a + bj, or complex(a, b), the real part a and the imaginary part b of the plural It is floating point type.
  • Long integers can also use lowercase "L", but it is recommended that you use uppercase "L" to avoid confusion with the number "1". Python uses "L" to display long integers.
  • Python also supports complex numbers, which consist of real and imaginary parts, which can be represented by a + bj, or complex(a,b). The real part a and the imaginary part b of the complex number are both floating point type

Python Number Type conversion

int(x [,base ]) willxConvert to an integer
long(x [,base ]) willxConvert to a long integer
float(x ) willxConvert to a floating point number
complex(real [,imag ]) Create a plural
str(x ) Object x Convert to string
repr(x ) Object x Convert to an expression string
eval(str ) Used to calculate valid in a stringPythonExpression and return an object
tuple(s ) Sequence s Convert to a tuple
list(s ) Sequence s Convert to a tuple...
chr(x ) Convert an integer to a character
unichr(x ) Convert an integer toUnicodecharacter
ord(x ) Convert a character to its integer value
hex(x ) Convert an integer to a hex string
oct(x ) Convert an integer to an octal string 

Python math module, cmath module

The functions commonly used in mathematical operations in Python are basically in the math module and the cmath module.

The Python math module provides a number of mathematical operations on floating point numbers.

The Python cmath module contains some functions for complex operations.

The function of the cmath module is basically the same as the math module function. The difference is that the cmath module operates on complex numbers, and the math module operates on mathematical operations.

To use the math or cmath function you must first import:

import math

welookups is optimized for learning.© welookups 2018 -
All Right Reserved and you agree to have read and accepted our term and condition