DEV Community

Lourenço Costa
Lourenço Costa

Posted on • Edited on

Python course: Numbers

In Python, numbers can be represented as three different types:

Int

Short for "integer". This type is used to represent whole numbers. Being positive, negative, or zero.

a = 5
b = 123456789101112
c = -45
d = 0

# Use type(<some_variable>) to return the type of a variable:

print(type(a)) # => <class 'int'>
print(type(b)) # => <class 'int'>
print(type(c)) # => <class 'int'>
print(type(d)) # => <class 'int'>
Enter fullscreen mode Exit fullscreen mode

Float

Also can be positive, negative or zero. It's used to represent decimal numbers. Floats can also be used to represent scientific notation, adopting "e" to indicate the power of 10.

a = 1.50
b = 0.0
c = -48.68
d = 4e3 # scientific notation, equals to 4000.0 
e = 4e-3 # scientific notation, equals to 0.004

print(type(a)) # => <class 'float'> 
print(type(b)) # => <class 'float'> 
print(type(c)) # => <class 'float'> 
print(type(d)) # => <class 'float'> 
print(type(e)) # => <class 'float'>
Enter fullscreen mode Exit fullscreen mode

Complex

A "complex" is a number with a real and an imaginary part, where the imaginary part is a multiple of the imaginary unit "j".

a = 3 + 5j 
b = 5j
c = -5j

print(type(a)) # => <class 'complex'> 
print(type(b)) # => <class 'complex'> 
print(type(c)) # => <class 'complex'>
Enter fullscreen mode Exit fullscreen mode

Be aware that you are eligible get a Wise card or your first international transfer, up to 500 EUR, free! I've been using their service for years and it's a great way to send/receive money abroad, creating disposable virtual cards, and more. Get it here: Sponsored link.

By now you may have heard of ElevenLabs. Their AI voice cloning service is simply off the charts. Check them out: Sponsored link.


Follow me around:
LinkedIn Buy me a coffee GitHub Dev.to

Top comments (0)