Python numbers are a data type that stores numeric values. It’s an immutable data type – means that it can change the value of the data variable in a new value allocated. In this tutorial, you will learn about Python number data types with examples.
Python Numbers Simple example
number = 14 print(1234567890) print(type(number))
Python Numbers Types
Python supports integers, floating point numbers and complex numbers. They are defined as :
complexclass in Python.
A whole number (Int or integer ), + positive or – negative, without decimals of no limit length.
number = 14 long_no = 3523434362343534343 negative_no = -3255522 print(type(number)) print(long_no) print(negative_no)
Output : <class ‘int’>
A Float or floating-point number is a number that can positive or negative and containing one or more decimals. Float numbers can also be scientific numbers with an “e” to indicate the power of 10.
no1 = 18.10 no2 = 1.0 no3 = -35.59 print(type(no1)) print(no2) print(no3)
Output : <class ‘float’>
Complex Type (Imaginary numbers)
Complex numbers are written with a “j” as the imaginary part. In python, you can put ‘j’ or ‘J’ after a number to make it imaginary, so you can write complex literals easily:
x = 7+5j print(type(x)) print(x)
Output : <class ‘complex’>
Do comment if you have any doubt and suggestion on this tutorial.
Note : This example (Project) is developed in PyCharm 2018.2 (Community Edition)
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
All Examples of Numbers and types are in Python 3, so it may change its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.