Pruned10216
Seasoned Veteran
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
400 XP
In this tutorial you will learn:
Numbers in Python
In the previous tutorial we learned what are String data types are, how they can be declared and accessed. In this tutorial we will learn the usage of different number types in Python.
myNum =
24
In Python there are different number types and the most important once are Float, Int and Complex numbers.
Floating point number
A number which is either negative or positive and contains a fraction which is shown by a decimal point is known as a floating point number.
For example:
3.14, 2.33, 4.88
PI = 3.14
myFloat = 2.33
myFloat2 = 4.88
Integers
Whole numbers either negative, positive numbers are considered integers.
myInteger1 = 33
myInteger2 = 232323
myInteger3 = 5959590002
Complex Numbers
One of the most interesting features of Python is its ability to handle complex numbers. Complex numbers are donated by j in python. All complex numbers contain a real part and the imaginary part.
myComplex1 = 3 + 5j
myComplex2 = 2j
myComplex3 = -7 + 2j
print(myComplex1 + myComplex2) #3+7j
This functionality of Python to handle complex numbers definitely makes it an ideal language for handling mathematical calculations.
Book traversal links for Python Numbers
- Numbers in Python
- Integers
- Floating point numbers
- Complex numbers
Numbers in Python
In the previous tutorial we learned what are String data types are, how they can be declared and accessed. In this tutorial we will learn the usage of different number types in Python.
myNum =
24
In Python there are different number types and the most important once are Float, Int and Complex numbers.
Floating point number
A number which is either negative or positive and contains a fraction which is shown by a decimal point is known as a floating point number.
For example:
3.14, 2.33, 4.88
PI = 3.14
myFloat = 2.33
myFloat2 = 4.88
Integers
Whole numbers either negative, positive numbers are considered integers.
myInteger1 = 33
myInteger2 = 232323
myInteger3 = 5959590002
Complex Numbers
One of the most interesting features of Python is its ability to handle complex numbers. Complex numbers are donated by j in python. All complex numbers contain a real part and the imaginary part.
myComplex1 = 3 + 5j
myComplex2 = 2j
myComplex3 = -7 + 2j
print(myComplex1 + myComplex2) #3+7j
This functionality of Python to handle complex numbers definitely makes it an ideal language for handling mathematical calculations.
Book traversal links for Python Numbers
- ‹ Python Boolean
- Up
- Python Strings ›