Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
py-quickstart/docs/conditionals/example-9.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (30 sloc)
1.02 KB
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
# example-9.py | |
# Common evaluations and their outcomes | |
variable_1 = 4 | |
variable_2 = 2 | |
variable_3 = 3 | |
variable_4 = 5 | |
# Simple math functionality | |
print(variable_1 + variable_2) | |
print(variable_1 - variable_2) | |
print(variable_1 * variable_2) | |
print(variable_1 / variable_2) # / always becomes a floating number | |
print(variable_1 % variable_2) | |
print(variable_1 // variable_2) | |
# Let's do some type checking to prove it | |
print(type(variable_1 + variable_2)) | |
print(type(variable_1 - variable_2)) | |
print(type(variable_1 * variable_2)) | |
print(type(variable_1 / variable_2)) | |
print(type(variable_1 % variable_2)) | |
print(type(variable_1 // variable_2)) | |
# String concatination | |
# this uses the + in an interesting way | |
string_1 = "hey" | |
string_2 = "you" | |
print(string_1 + " " + string_2 + "!") | |
print(type(string_1 + " " + string_2 + "!")) | |
# interesting evaluations that still happen from left to right | |
# mostly... | |
print(variable_1 + variable_2 * variable_3 + variable_4) | |
print(variable_4 + variable_1 * variable_2 - variable_3) |