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

Designed by IITians, only for AI Learners.

Internship Partner

In Association with

In collaboration with

Designed by IITians, only for AI Learners.

Internship Partner

In Association with

In collaboration with

New to InsideAIML? Create an account

Employer? Create an account

Designed by IITians, only for AI Learners.

Internship Partner

In Association with

In collaboration with

Enter your email below and we will send a message to reset your password

Designed by IITians, only for AI Learners.

Internship Partner

In Association with

In collaboration with

By providing your contact details, you agree to our Terms of Use & Privacy Policy.

Already have an account? Sign In

Designed by IITians, only for AI Learners.

Internship Partner

In Association with

In collaboration with

By providing your contact details, you agree to our Terms of Use & Privacy Policy.

Already have an account? Sign In

Download our e-book of Introduction To Python

Matplotlib - Object-oriented InterfaceMatplotlib - MultiplotsCNTK - Creating First Neural NetworkMatplotlib - Working with ImagesMicrosoft Cognitive Toolkit (CNTK) - CPU and GPUPython Forensics - Memory and ForensicsPython Blockchain - Scope and ConclusionDiscuss Microsoft Cognitive ToolkitMatplotlib - Twin AxesMatplotlib - Subplot2grid() Function View More

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 choosing the right estimator for the machine learning problem? How to Write Python ZIP File? How to extracting text from PDF file using python How can a web interface execute a .py file from a PHP file? What methods can we use to differentiate between correlated and uncorrelated variables in a regression analysis? How to leave/exit/deactivate a Python virtualenvironment Join Discussion

4.5 (1,292 Ratings)

589 Learners

Sep 30th (7:00 PM) 1117 Registered

Balasaheb Garule

2 years ago

Introduction

- Python Int
- Python Float
- Python Complex Number

Type Conversion

Arithmetic Operations

- Addition.
- Subtraction.
- Multiplication.
- Division
- Integer Division
- Exponents
- The Modulus Operator

Summary

Numeric data is stored into numbers data type in python. Number data structures are immutable i.e. you never change the value of data type or if you change the value then a new object is created. It stores positive, negative, decimal, floating-point numbers, and complex numbers.

In python, there are following numeric data types are available

- Integers
- Floating-point numbers
- Complex Numbers

The integer in the python data type represents whole numbers. A number is positive or negative, the length of the number is unlimited. We can declare a very large integer value using the python int type.

e.g.

```
n = 10000000000000000001
print(type(n))
```

Output

`<class 'int'>`

Python float is a decimal data type. It will be used for declaring floating-point values. Values may be positive or negative.

e.g.

```
fp = 3.14
print(type(fp))
```

Output

`<class 'float'>`

The complex number contains two parts: the real and imaginary part with j.

We can access the real and imaginary parts with a.real and a.imag, respectively.

e.g.

```
c = 3+4j
print(type(c))
print(c.real)
print(c.imag)
```

Output

```
<class 'complex'>
3.0
4.0
```

We can convert one type of variable into other types of variable. The complex type of variable is not converted into any other type. It is also known as typecasting. For this we use int(), float(), str(), and complex() methods.type conversion between float to integer remove the decimal value from float value.

e.g.

```
p = 10 # int
q = 3.14 # float
r = 2+4j # complex
print(“convert from python int to float”)
x = float(p)
print(type(x))
print(x)
print(“convert from python float to int”)
y = int(q)
print(type(y))
print(y)
print(“convert from python int to complex”)
z = complex(p)
print(type(z))
print(z)
print(“convert from python int to string”)
s = str(p)
print(type(s))
print(s)
```

Output

```
convert from python int to float
<class 'float'>
10.0
convert from python float to int
<class 'int'>
3
convert from python int to complex
<class 'complex'>
(10+0j)
convert from python int to string
<class 'str'>
10
```

Adding variable values using the “+” operator. Addition performs on same as well as a different type of variable. The addition of int and float is always a return a python float value.

```
#python program to add two numbers
# integer number addition
num1 = 10
num2 = 20
add = num1+ num2
print(“Integer Addition : ”,add)
# float number addition
num1 = 10
num2 = 2.5
add = num1 + num2
print(“Float Addition : ”,add)
#Complex number addition
num1 = 5+3j
num2 = 2
add = num1 + num2
print(“Complex Addition : ”,add)
# Real and imaginary parts are added to get the result.
```

Output

```
Integer Addition : 30
Float Addition : 12.5
Complex Addition : (7+3j)
```

Subtract variable value using “-” operator. Subtraction performs on the same as well as a different type of variable. Subtraction of int and float is always returned a python float value.

```
#python program to subtract two numbers
# integer number Subtraction
num1 = 10
num2 = 20
sub = num1- num2
print(“Integer Subtraction: ”,sub)
# float number Subtraction
num1 = 10
num2 = 2.5
sub = num1 - num2
print(“Float Subtraction: ”,add)
#Complex number Subtraction
num1 = 5+3j
num2 = 2
sub = num1 - num2
print(“Complex Subtraction: ”,sub)
# Real and imaginary parts are Subtract to get the result.
```

Output

```
Integer Subtraction : -10
Float Subtraction : 7.5
Complex Subtraction : (3+3j)
```

Multiplication is done using the “*” operator. Multiplication performs on the same as well as different types of variables. Multiplication of int and float is always returned a python float value.

```
#python program to Multiplication two numbers
# integer number Multiplication
num1 = 10
num2 = 20
mul = num1- num2
print(“Integer Multiplication: ”,mul)
# float number Multiplication
num1 = 10
num2 = 2.5
mul = num1 - num2
print(“Float Multiplication: ”, mul)
#Complex number Multiplication
num1 = 5+3j
num2 = 2
mul = num1 - num2
print(“Complex Multiplication: ”, mul)
# Real and imaginary parts are multiply by num2 value to get the result.
```

Output

```
Integer Multiplication : 200
Float Multiplication : 25.0
Complex Multiplication : (10+6j)
```

Division operation is done using the “/” operator. The division performs on the same as well as different types of variables. Division operation always returns a float value.

```
#python program to Division two numbers
# integer number Division
num1 = 10
num2 = 20
div = num1/ num2
print(“Integer Division: ”,div)
# float number Division
num1 = 10
num2 = 2.5
div = num1 / num2
print(“Float Division: ”, div)
#Complex number Division
num1 = 5+3j
num2 = 2
div = num1 / num2
print(“Complex Division: ”, div)
# Real and imaginary parts are divide by num2 value to get the result.
```

Output

```
Integer Division : 0.5
Float Division : 4.0
Complex Division : (2.5+1.5j)
```

To convert division operation value into integer use integer division.to perform this operation uses the “//” operator.it is also called a floor division operator.

e.g.

```
n = int(5.0/2)
print(n)
```

output

`2`

similar to

```
n = 5 // 2
print(n)
```

output

`2`

To calculate exponent use the “**” operator.

e.g.

```
n = 3**2
print(n)
```

output

`9`

```
m = 3 ** -1
print(m)
```

Output

`0.3333333333333333`

The modulus operator (%) returns a reminder of two values.

e.g.

```
r = 5 % 2
print(r)
```

output

`1`

In this blog, we learned about python numbers. Int(), float(), and complex() are the python number data types. We also learn about arithmetic operation, integer division, exponents, and modulus operators.

If you have any doubt about insideAIML’s python numbers blog, drop a comment below and we will get back to you.

Enjoyed reading this blog? Then why not share it with others. Help us make this AI community stronger.

To learn more about such concepts related to Artificial Intelligence, visit our blog page.

You can also ask direct queries related to Artificial Intelligence, Deep Learning, Data Science and Machine Learning on our live discussion forum.

Keep Learning. Keep Growing.