Photo by Glenn Carstens-Peters on Unsplash
Python Numbers
all you need to know about python numbers as a beginner.
INTRODUCTION:
Hey Folks, How you doin'? HOPE u all are doing well! so I am back with another python blog Enjoy!!!
Python Numbers:
There are three numeric types in Python:
- int
- float
- complex
numeric type variables are created when you assign a value to them: Example: x = 25 # int y = 2.5 # float z = 9i # complex
to verify the type of any object in Python, use the type() function:
Example: print(type(x)) (output will be int according to the example used above).
Int: Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
Float: Float, or "floating point number" is a number, positive or negative, containing one or more decimals.
Float can also be scientific numbers with an "e" to indicate the power of 10.
Example: x = 35e3
Complex: Complex numbers are written with a "j" as the imaginary part.
Example: x = 2+7j
Type Conversion: You can convert from one type to another with the int(), float(), and complex() methods:
#convert from int to float: a = float(x)
#convert from float to int: b = int(y)
#convert from int to complex: c = complex(x)
Quiz:
Here is a little quiz for you to solve, first, create a variable x and assign a number or value to it in integers now you have to convert the value of x into float and then print the type.
Note: You cannot convert complex numbers into another number type.
That's it for today guys if you like this blog make sure to give it a huge thumbs up ur reviews matters a lot to me Thank you for reading Enjoy.