INTRODUCTION:
Hey Folks, How you doin'? HOPE u all are doing well! so I am back with another python blog Enjoy!!!
OK, so today we are going to talk about Python Numbers in detail.
There are three numeric types in Python:
- int
- float
- complex
Example:
- x = 1 # int
- y = 2.8 # float
- z = 1j # complex
Int: Int, or integer, is a whole number, positive or negative, without decimals, of any length.
Example:
x = 1
Float:
A float is a number, positive or negative, containing one or more decimals. It is also known as the "floating point number"
Example:
x = 1.10
Complex:
Complex numbers are written with a "j" as the imaginary part (like x = 3+5j).
Type Conversion:
You can convert from one type to another with the int(), float(), and complex() methods:
Example:
x = 1 # int y = 2.8 # float z = 1j # complex
#convert from int to float: a = float(x)
#convert from float to int: b = int(y)
#convert from int to complex: c = complex(x).
Mini Tip: To verify the type of any object in Python, use the type() function:
Example:
print(type(x))to verify the type of x
So, guys, that's all for today hope you guys enjoyed my blog!