Python Numbers

Number data types store numeric values. They are immutable data types, means that 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 −

Topics You May Be Interested In
Python - Sorting Algorithms Python - Word Replacement
Python - Telnet Python Basic Operators
Python - Text Processing Environment Python Modules
Python - Sorting Lines Python Cgi Programming
```del var
del var_a, var_b
```

Python supports four different numerical types −

Examples

Here are some examples of numbers

int long float complex
10 51924361L 0.0 3.14j
100 -0x19323L 15.20 45.j
-786 0122L -21.9 9.322e-36j
080 0xDEFABCECBDAECBFBAEL 32.3+e18 .876j
-0490 535633629843L -90. -.6545+0J
-0x260 -052318172735L -32.54e100 3e+26J
0x69 -4721885298529L 70.2-E12 4.53e-7j

Number Type Conversion

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

Mathematical Functions

Python includes following functions that perform mathematical calculations.

Sr.No. Function & Returns ( description )
1 abs(x)

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

Topics You May Be Interested In
Python Overview Python - Http Client
Python Decision Making Python - Text Processing Introduction
Python - Ds Home Python - Synonyms And Antonyms
Python - Ds Introduction Python - Spelling Check
Python - Arrays Python Files I/o
2 ceil(x)

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

3 cmp(x, y)

-1 if x < y, 0 if x == y, or 1 if x > y

4 exp(x)

The exponential of x: ex

5 fabs(x)

The absolute value of x.

Topics You May Be Interested In
Python Numbers Python - Http Response
Python - Lists Python - Google Maps
Python - Maps Python - Sorting Lines
Python - Amortized Analysis Python - Capitalize And Translate
Python - Algorithm Justification Python - Corpora Access
6 floor(x)

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

7 log(x)

The natural logarithm of x, for x> 0

8 log10(x)

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

9 max(x1, x2,...)

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

Topics You May Be Interested In
Python - Tuples Python - Pretty Print Numbers
Python - Dictionary Python - Process Word Document
Python - Network Programming Python - Frequency Distribution
Python - Building Urls Python Numbers
Python - Web Servers Python Lists
10 min(x1, x2,...)

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

11 modf(x)

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.

12 pow(x, y)

The value of x**y.

13 round(x [,n])

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.

Topics You May Be Interested In
Python Environment Setup Python - Network Interface
Python Variable Types Python - Web Servers
Python Numbers Python - Proxy Server
Python - Queue Python - Text Processing Introduction
Python - Ip Address Python - Frequency Distribution
14 sqrt(x)

The square root of x for x > 0

Random Number Functions

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

Sr.No. Function & Description
1 choice(seq)

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

2 randrange ([start,] stop [,step])

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

Topics You May Be Interested In
Python Tutorial Python - Http Client
Python - Ds Home Python - Databases And Sql
Python - Recursion Python - Email Messages
Python - Sorting Algorithms Python Decision Making
Python - Http Requests Python Regular Expressions
3 random()

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

4 seed([x])

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

5 shuffle(lst)

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

6 uniform(x, y)

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

Topics You May Be Interested In
Python Loops Python - Sockets Programming
Python Xml Processing Python - Email Messages
Python - Ds Home Python - Pretty Print Numbers
Python - Dictionary Python - Text Summarization
Python - Maps Python Overview

Trigonometric Functions

Python includes following functions that perform trigonometric calculations.

Sr.No. Function & Description
1 acos(x)

Return the arc cosine of x, in radians.

2 asin(x)

Return the arc sine of x, in radians.

3 atan(x)

Return the arc tangent of x, in radians.

Topics You May Be Interested In
Python Lists Python - Http Client
Python Extension Programming With C Python - Telnet
Python - Maps Python - Remote Procedure Call
Python - Recursion Python - Capitalize And Translate
Python - Backtracking Python Overview
4 atan2(y, x)

Return atan(y / x), in radians.

5 cos(x)

Return the cosine of x radians.

6 hypot(x, y)

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

7 sin(x)

Return the sine of x radians.

Topics You May Be Interested In
Python Tutorial Python - Algorithm Analysis
Python Xml Processing Python-network Programming Introduction
Python - Hash Table Python - Text Translation
Python - Graphs Python Tutorial
Python - Searching Algorithms Python Basic Syntax
8 tan(x)

Return the tangent of x radians.

9 degrees(x)

Converts angle x from radians to degrees.

Converts angle x from degrees to radians.

Mathematical Constants

The module also defines two mathematical constants −

Sr.No. Constants & Description
1

pi

The mathematical constant pi.

2

e

The mathematical constant e.

+
Ans: Python Loops - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Decision Making - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Basic Operators - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Numbers - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Strings - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Lists - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Tuples - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Dictionary - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Date and Time - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Functions - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Modules - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Files I/O - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Exceptions Handling - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Object Oriented - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Regular Expressions - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python CGI Programming - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python MySQL Database Access - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Network Programming - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..

Rating - NAN/5
461 views