#### World's Best AI Learning Platform with profoundly Demanding Certification Programs

Designed by IITians, only for AI Learners.

Designed by IITians, only for AI Learners.

New to InsideAIML? Create an account

Employer? Create an account

Download our e-book of Introduction To Python

Exception Type: JSONDecodeError at /update/ Exception Value: Expecting value: line 1 column 1 (char 0) How can I write Python code to change a date string from "mm/dd/yy hh: mm" format to "YYYY-MM-DD HH: mm" format? How to leave/exit/deactivate a Python virtualenvironment How Indentation is Parsed? What is use of Heat map ? How to plot heat map? VS code interactive mode What is the process to generate a receipt on Android with the help of Python? Why not getting result of a as [4, 7,8,3,2] Join Discussion

4.5 (1,292 Ratings)

559 Learners

Apr 6th (7:00 PM) 190 Registered

Neha Kumawat

a year ago

- Introduction
- Numerical Types

1. int (signed integers)

2. float (floating point real values)

3. complex (complex numbers)

- Number Type Conversion

- Mathematical Functions

- Random Number Functions

- Trigonometric Functions

- Mathematical Constants

Number data types store numeric values. They are immutable data types. This means, changing the value of a number data type results in a newly allocated object.

Number objects are created when you assign a value to them. For example −

```
var1 = 1
var2 = 10
```

You can also delete the reference to a number object by using the del statement. The syntax of the del statement is −

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

You can delete a single object or multiple objects by using the del statement. For example −

```
del var
del var_a, var_b
```

Python supports different numerical types −

They are often called just integers or ints. They are positive or negative whole numbers with no decimal point. Integers in Python 3 are of unlimited size. Python 2 has two integer types - int and long. There is no 'long integer' in Python 3 anymore.

Also called floats, they represent real numbers and are written with a decimal point dividing the integer and the fractional parts. Floats may also be in scientific notation, with E or e indicating the power of 10 (2.5e2 = 2.5 x 102 = 250).

They are of the form a + bJ, where a and b are floats and J (or j) represents the square root of -1 (which is an imaginary number). The real part of the number is a, and the imaginary part is b. Complex numbers are not used much in Python programming.

It is possible to represent an integer in hexa-decimal or octal form

```
>>> number = 0xA0F #Hexa-decimal
>>> number
2575
>>> number = 0o37 #Octal
>>> number
31
```

Here are some examples of numbers.

A complex number consists of an ordered pair of real floating-point numbers denoted by a &plus bj, where a is the real part and b is the imaginary part of the complex number.

Python converts numbers internally in an expression containing mixed types to a common type for evaluation. Sometimes, you need to coerce a number explicitly from one type to another to satisfy the requirements of an operator or function parameter.

- Type int(x) to convert x to a plain integer.

- Type long(x) to convert x to a long integer.

- Type float(x) to convert x to a floating-point number.

- Type complex(x) to convert x to a complex number with real part x and imaginary part zero.

- Type complex(x, y) to convert x and y to a complex number with real part x and imaginary part y. x and y are numeric expressions

Python includes the following functions that perform mathematical calculations.

The absolute value of x: the (positive) distance between x and zero.

The ceiling of x: the smallest integer not less than x.

cmp(x, y)

-1 if x < y, 0 if x == y, or 1 if x > y. Deprecated in Python 3. Instead use return (x>y)-(x

The exponential of x: ex

The absolute value of x.

The floor of x: the largest integer not greater than x.

The natural logarithm of x, for x > 0.

The base-10 logarithm of x for x > 0.

The largest of its arguments: the value closest to positive infinity

The smallest of its arguments: the value closest to negative infinity.

The fractional and integer parts of x in a two-item tuple. Both parts have the same sign as x. The integer part is returned as a float.

The value of x**y.

x rounded to n digits from the decimal point. Python rounds away from zero as a tie-breaker: round(0.5) is 1.0 and round(-0.5) is -1.0.

The square root of x for x > 0.

Random numbers are used for games, simulations, testing, security, and privacy applications. Python includes the following functions that are commonly used.

A random item from a list, tuple, or string.

A randomly selected element from range(start, stop, step).

A random float r, such that 0 is less than or equal to r and r is less than 1

Sets the integer starting value used in generating random numbers. Call this function before calling any other random module function. Returns None.

Randomizes the items of a list in place. Returns None.

A random float r, such that x is less than or equal to r and r is less than y.

Python includes the following functions that perform trigonometric calculations.

Return the arc cosine of x, in radians.

Return the arc sine of x, in radians.

Return the arc tangent of x, in radians.

Return atan(y / x), in radians.

Return the cosine of x radians.

Return the Euclidean norm, sqrt(x*x + y*y).

Return the sine of x radians.

Return the tangent of x radians.

Converts angle x from radians to degrees.

Converts angle x from degrees to radians.

The module also defines two mathematical constants −

pi

The mathematical constant pi.

e

The mathematical constant e.

Like the Blog, then Share it with your friends and colleagues to make this AI community stronger.

To learn more about nuances of Artificial Intelligence, Python Programming, Deep Learning, Data Science and Machine Learning, visit our insideAIML blog page.

Keep Learning. Keep Growing.