-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathoperators.py
More file actions
executable file
·49 lines (30 loc) · 897 Bytes
/
operators.py
File metadata and controls
executable file
·49 lines (30 loc) · 897 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
"""
In python everything is an object.
There is operator overload: every operator has a correponding method
In Python, methods that can become operators are prefixed and suffixed by `__`.
For example:
- `==` and `__eq__()`
- `+` and `__add__()`
- `**` and `__pow__()`
- `//` and `__TODO__()`
Built-in classes like `int` simply implement those methods.
"""
assert 0 == 0
assert 2 * 3 == 6
# C like division arithmetic:
assert 1 / 2 == 0
assert 1 / 2.0 == 0.5
assert 1 / float(2) == 0.5
# Floor division:
assert 9.0 // 2.0 == 4
# pow:
assert 2 ** 3
if '## boolean operator':
assert not True == False
assert True and False == False
assert True or False == True
if '## chained comparison':
# Insane sugar:
# http://stackoverflow.com/questions/24436150/how-does-interval-comparison-work
assert 1 < 2 < 3 < 4 < 5