Last active
December 27, 2015 14:28
-
-
Save kaydell/7340286 to your computer and use it in GitHub Desktop.
A Python Script That Demonstrates int and float literals and how to get the type of any value.
This file contains hidden or 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
#!/usr/bin/env python3 | |
""" | |
Script version: Python 3 (may not work in Python 2) | |
This script demonstrates setting a variable to an int and to a float. | |
A float is sometimes called a "real" and an int is also known as a | |
"whole number". | |
The point of this demo: | |
1. Without a decimal point, 10 is an int | |
2. With a decimal point, 10.0 is a float (aka real) | |
3. Every variable has both a type and a value | |
4. You can see the type of any variable by using the function called "type()" | |
""" | |
# x as an int | |
# set x to 10 | |
x = 10 | |
# print the type of x (should be an int) | |
print("type(x) %s" % type(x)) | |
# y as a float | |
# set y to 10.0 | |
y = 10.0 | |
# print the type of y (should be float) | |
print("type(y) %s" % type(y)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment