**Article by:** Manish Methani

**Last Updated:** October 7, 2021 at 8:04am IST

- Numeric Data Types in Python Python has three main numeric data types:

- Integers (int): Whole numbers, positive or negative, without a decimal point.
- Floating-point numbers (float): Numbers with a decimal point or an exponent notation.
- Complex numbers (complex): Numbers with a real and imaginary part.

Here are some examples:

# Integers x = 5 y = -10 z = 0 # Floating-point numbers a = 3.14 b = 1.23e-5 # Complex numbers c = 3 + 4j d = complex(1, -2)

2. Basic Arithmetic Operations

Python supports all basic arithmetic operations for numerical data types. Here are some examples:

x = 5 y = 3 # Addition z = x + y # Output: 8 # Subtraction z = x - y # Output: 2 # Multiplication z = x * y # Output: 15 # Division z = x / y # Output: 1.6666666666666667 # Floor Division z = x // y # Output: 1 # Modulo z = x % y # Output: 2 # Exponentiation z = x ** y # Output: 125

3. Type Conversion

Python allows you to convert numerical data types from one to another. Here's an example:

x = 5 y = 3.14 # Convert x to a floating-point number and add it to y z = float(x) + y print(z) # Output: 8.14

In this example, we convert the integer "x" to a floating-point number using the `float()`

function and add it to the floating-point number "y".

4. Built-in Functions Python has several built-in functions for working with numbers. Here are some examples:

# Absolute value x = abs(-10) # Output: 10 # Round to a certain number of decimal places y = round(3.14159, 2) # Output: 3.14 # Maximum and minimum values z = max(1, 2, 3) # Output: 3 a = min(4, 5, 6) # Output: 4

5. Math Module

Python also has a math module that provides additional mathematical functions. Here's an example:

import math # Square root x = math.sqrt(25) # Output: 5.0 # Trigonometric functions y = math.sin(0) # Output: 0.0 z = math.cos(math.pi) # Output: -1.0

6. Floats

Floats are used to represent real numbers with decimal points. They are also known as floating-point numbers. In Python, float is represented by `float`

class. We can create a float variable by assigning a value with a decimal point to it.

Here's an example:

# Example of float x = 3.14 y = 2.5 print(x) print(y)

Output:

3.14 2.5

We can also use mathematical operations with floats:

# Example of float with mathematical operations x = 3.14 y = 2.5 z = x + y print(z)

Output:

5.64

Complex numbers are used to represent numbers with a real and imaginary part. In Python, complex numbers are represented by `complex`

class. We can create a complex number by specifying the real and imaginary parts separated by a `+`

or `-`

sign.

Here's an example:

# Example of complex number x = 2 + 3j y = 4 - 2j print(x) print(y)

Output:

(2+3j) (4-2j)

We can also use mathematical operations with complex numbers:

# Example of complex number with mathematical operations x = 2 + 3j y = 4 - 2j z = x + y print(z)

Output:

(6+1j)

We can convert one type of number into another using type conversion functions. Here are some type conversion functions in Python:

`int(x)`

converts x to an integer.`float(x)`

converts x to a floating-point number.`complex(x)`

converts x to a complex number with a zero imaginary part.`complex(x, y)`

converts x and y to a complex number with real part x and imaginary part y.

Here are some examples:

# Example of type conversion x = 10 y = 3.14 z = 2 + 3j # convert x to float a = float(x) # convert y to int b = int(y) # convert z to float c = float(z) print(a) print(b) print(c)

Output:

10.0 3 (2+3j)

We have covered the basics of Python Numbers in this tutorial.

10 OS Interview Questions you must know in 2024

10 Angular Interview Questions you must know in 2024

10 Javascript Interview Questions you must know in 2024

Top 10 DSA Interview Questions You should not miss

Top 10 Web Development Interview Questions

Introduction to Next.js

Altina Schinasi: Celebrating the Visionary Designer of Cat-Eye Frames | Google Doodle Tribute

Best Niche for Blogging in USA: A Comprehensive Guide

18 Must-Do Activities for Computer Science Students in College

13 Essential Things Solopreneurs need to know in 2024

25 Practical ways to earn money online

The Power of Gratitude - A Journey to Personal Growth

Top 5 Technology Trends That Are Shaping Our Future

5 Books You Need to Read Right Now

How to answer tell me about yourself?

What Angular feature transforms data before displaying it in the view?

Which widget is used in Flutter to create a button?

6 Mobile App Ideas That You Can Start in 2024

Flutter Widget Showdown: Exploring the Developers Favorite for Layouts!

Mobile App

For Engineers.

Mock Tests.

Test your C Programming skills with this comprehensive mock test on C Programming.

Take TestSolve most asked Interview Questions on Flutter and Test your foundational skills in flutter.

Take TestSolve most asked GATE Questions in Operating Systems and test your Gate Score.

Take TestThis is a mock test designed to help you assess your knowledge and skills in HTML and CSS.

Take TestSolve most asked GATE Questions in Data Structures and Algorithms and test your Gate Score.

Take Test