Skip to content

Python Numbers & Types Tutorial with Example

  • by

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 and Types Tutorial with Example

Python Numbers Simple example 

Here directly showing the number and using a variable. Printing a value and type in the console. In output showing its type is class – <class ‘int’>

number = 14

print(1234567890)
print(type(number))

Output: 1234567890
<class ‘int’>

Python Numbers Types

Python supports integers, floating point numbers and complex numbers. They are defined  as :

  •  int,
  •  float
  • and complex class in Python.

Int Type

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’>
3523434362343534343
-3255522

Float Type

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’>
1.0
-35.59

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’>
(7+5j)

Do comment if you have any doubt and suggestion on this tutorial.

Note : This example (Project) is developed in PyCharm 2018.2 (Community Edition)
JRE: 1.8.0
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6
Python 3.7
All Examples of Numbers and types are in Python 3, so it may change its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading