Skip to content

Commit 78ca7af

Browse files
authored
Added Vector class
1 parent 6679744 commit 78ca7af

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Vector:
2+
"""
3+
Constructor
4+
5+
self: a reference to the object we are creating
6+
vals: a list of integers which are the contents of our vector
7+
"""
8+
def __init__(self, vals):
9+
self.vals = vals # Notice! We are using the keyword self to create a field or property (for Javascript users)
10+
print("Assigned values ", vals, " to vector.")
11+
12+
"""
13+
String Function
14+
15+
Converts the object to a string in readable format for programmers
16+
"""
17+
def __str__(self):
18+
return str(self.vals) # Returns the contents of the vector
19+
20+
vec = Vector([2, 3, 2])
21+
print(str(vec)) # [2, 3, 2]

0 commit comments

Comments
 (0)