In this Python tutorial we are going to talk about Python Data Types, especially we are going to create example on Python Numbers Data Types. so when you create a value in Python, every value in Python has it’s own data type. for example variables can store data of different types. there are different data types that you can use. but in this tutorial we are going to create examples on numbers. also you can watch the complete video tutorial for this article.
ٌWatch the complete Video Tutorial
Python Numbers
So Python Numbers or Numeric are divided in to three parts, Integer, Float and Complex Number.
Integers
The size of an integer is limited only by the machine’s memory, so integers
hundreds of digits long can easily be created and worked with although they
will be slower to use than integers that can be represented natively by the
machine’s processor.
1 2 |
x = 10 print("Number is " , x) |
This is the result
1 2 3 |
Number is 10 Process finished with exit code 0 |
Also you can find the type of a value by using type() function.
1 2 |
x = 10 print("Type is : " , type(x)) |
This is the result.
1 2 3 |
Type is : <class 'int'> Process finished with exit code 0 |
Floating
Python provides three kinds of floating-point values: the built-in float and
complex types, and the decimal.Decimal type from the standard library. All three
are immutable. Type float holds double-precision floating-point numbers
whose range depends on the C (or C# or Java) compiler Python was built with,
they have limited precision and cannot reliably be compared for equality.
Numbers of type float are written with a decimal point, or using exponential
notation, for example.
1 |
0.0, 4., 5.7, -2.5, -2e9, 8.9e-4 |
1 2 |
x = 6.5 print(x) |
The output is
1 2 3 |
6.5 Process finished with exit code 0 |
Also you can find the type of a value by using type() function.
1 2 |
x = 6.5 print("Type is : ", type(x)) |
This is the output
1 2 3 |
Type is : <class 'float'> Process finished with exit code 0 |
Complex Numbers
The complex data type is an immutable type that holds a pair of floats, one
representing the real part and the other the imaginary part of a complex
number. these are the examples.
1 2 3 4 5 |
x= -50.5+2.125j print(x) print(x.real) print(x.imag) |
This is the output.
1 2 3 4 5 |
(-50.5+2.125j) -50.5 2.125 Process finished with exit code 0 |
Also you can find the type of a value by using type() function.
1 2 3 |
x= -50.5+2.125j print("Type is : " , type(x)) |
This is the output.
1 2 3 |
Type is : <class 'complex'> Process finished with exit code 0 |
Subscribe and Get Free Video Courses & Articles in your Email