1️⃣ Numeric
Numeric Datatype stores data in the form of numbers. Numeric information can be of different type like whole numbers, decimal numbers, floating numbers or complex numbers. There are 3 numeric data types present in python:
Integers(int)
Float(float)
Complex(complex)
1) Integers(int):
Python integers are whole numbers without containing decimal point. Integers can be zero, positive or negative numbers. We can define integers in python having unlimited length. Variables containing interger values are of <class ‘int’> type. Remember you can not define interger variable with leading zeros, it will show SyntaxError.
💻 Example:
1 2 3 4 5 6 7 8 9 | x = 0
print(type(x))
a = 10
print(type(a))
b = 20000000000000
print(type(b))
c = -100
print(type(c))
a = 010
|
✅ Output:
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
SyntaxError: leading zeros in decimal integer literals are not permitted;
2) Float(float):
Numbers containing decimal point are of float datatypes in python. Float datatype can be zero, positive or negative numbers containing decimal point. Variables containing float values are of <class ‘float’> type.
💻 Example:
1 2 3 4 5 6 7 8 | x = 0.0
print(type(x))
a = 10.45
print(type(a))
b = 20000000000000.26
print(type(b))
c = -100.55
print(type(c))
|
✅ Output:
<class 'float'>
<class 'float'>
<class 'float'>
<class 'float'>
3) Complex(complex):
Complex numbers consist of real and imaginary parts. Variables containing complex number are of <class ‘complex’> type. In below example we have considered complex number: 8+9j, where 8 is real component and j is imaginary component. You can only use j or J for representing imaginary component. Python will show SyntaxError if you use other character to represent imaginary part.
💻 Example:
1 2 3 4 5 | x = 8 + 9j
print(type(x))
c = 7j
print(type(c))
b = 3+4i
|
✅ Output:
<class 'complex'>
<class 'complex'>
SyntaxError: invalid syntax
So those are numerical data types present in python. Go through below content to get more information.
Here are the quick notes on above topic:
Follow below video to clear the concepts practically.
Be prepared with below questions prior to your interview !
Frequently asked Interview Questions
What are the numeric data types in Python?
What is the difference between integers and float datatypes?
How are complex numbers represented in Python?