Last active
September 19, 2019 14:09
-
-
Save techstackmedia/bde3394f17c8867ee5c481ab794c5cc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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