forked from atheistpiece/ultimate-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
expression.py
28 lines (21 loc) · 938 Bytes
/
expression.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def main():
# This is a simple integer
x = 1
# Its value can used as part of expressions
print("Add integer", x + 1)
# An expression can be chained indefinitely. This concept of chaining
# expressions is powerful because it allows you to compose simple pieces
# of code into larger pieces of code over time
print("Multiply integers", x * 2 * 2 * 2)
# Division is a bit tricky in Python because it returns a result
# of type 'float' by default
print("Divide as float", x / 2)
# If an integer division is desired, then an extra slash
# must be added to the expression
print("Divide by integer", x // 2)
# Powers of an integer can be leveraged too. If you want more math
# features, then you will have to leverage the builtin `math` library,
# a third-party library or your own library
print("Power of integer", x * 2 ** 3)
if __name__ == "__main__":
main()