Skip to content

Instantly share code, notes, and snippets.

@techstackmedia
Last active September 19, 2019 14:09
Show Gist options
  • Save techstackmedia/bde3394f17c8867ee5c481ab794c5cc1 to your computer and use it in GitHub Desktop.
Save techstackmedia/bde3394f17c8867ee5c481ab794c5cc1 to your computer and use it in GitHub Desktop.
# Number - Integer, Float, Complex
# Integer
Integer in Python are numbers without decimal e.g 20
# A different data type can be converted to an integer
# Integer conversion is done with the int() function
book_price = 20
print(book_price)
# 20
book_price = '30'
print(int(book_price))
# 30
# Float
# Float in Python are numbers with decimal e.g. 20.0
# A different data type can be converted to a float
# Float conversion is done with the float() function
book_price = 20.0
print(book_price)
# 20.0
book_price = '30'
print(float(book_price))
# 30.0
# Complex
# A complex number, z takes the form "z = a + b(j)"
# a is a real part; b is an imaginary part
# j can also be in uppercase (J) in Python
# complex() function can be used to convert numbers to its type
complex_number = 3 + 14.3J
complex_number
# (3+14.3j)
z = complex(3, 14.3)
print(z)
# (13+14.3j)
# https://repl.it/@OsagieBello/Fathomable-Python-Programmig-Numbers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment