example-operator-overloading.py 578 Bytes
Newer Older
1
2
#!/usr/bin/env python
from __future__ import print_function
Wenzel Jakob's avatar
Wenzel Jakob committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import sys
sys.path.append('.')

from example import Vector2, Vector

v1 = Vector2(1, 2)
v2 = Vector(3, -1)

print("v1    = " + str(v1))
print("v2    = " + str(v2))
print("v1+v2 = " + str(v1+v2))
print("v1-v2 = " + str(v1-v2))
print("v1-8  = " + str(v1-8))
print("v1+8  = " + str(v1+8))
print("v1*8  = " + str(v1*8))
print("v1/8  = " + str(v1/8))
19
20
21
22
print("8-v1  = " + str(8-v1))
print("8+v1  = " + str(8+v1))
print("8*v1  = " + str(8*v1))
print("8/v1  = " + str(8/v1))
Wenzel Jakob's avatar
Wenzel Jakob committed
23
24
25
26
27

v1 += v2
v1 *= 2

print("(v1+v2)*2 = " + str(v1))