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
50
51
52
53
54
55
56
57
| class Vector:
def __init__(self, x, y):
self.x = x
self.y = y
def __add__(self, other):
# + 연산자
return Vector(self.x + other.x, self.y + other.y)
def __sub__(self, other):
# - 연산자
return Vector(self.x - other.x, self.y - other.y)
def __mul__(self, scalar):
# * 연산자
return Vector(self.x * scalar, self.y * scalar)
def __truediv__(self, scalar):
# / 연산자
return Vector(self.x / scalar, self.y / scalar)
def __floordiv__(self, scalar):
# // 연산자
return Vector(self.x // scalar, self.y // scalar)
def __mod__(self, scalar):
# % 연산자
return Vector(self.x % scalar, self.y % scalar)
def __pow__(self, power):
# ** 연산자
return Vector(self.x ** power, self.y ** power)
def __lshift__(self, other):
# << 연산자
return self.x << other.x, self.y << other.y
def __rshift__(self, other):
# >> 연산자
return self.x >> other.x, self.y >> other.y
def __and__(self, other):
# & 연산자
return self.x & other.x, self.y & other.y
def __or__(self, other):
# | 연산자
return self.x | other.x, self.y | other.y
def __xor__(self, other):
# ^ 연산자
return self.x ^ other.x, self.y ^ other.y
v1 = Vector(1, 2)
v2 = Vector(3, 4)
print(v1 + v2) # 벡터 덧셈
print(v1 * 2) # 벡터 스칼라 곱
|