Skip to content

Commit 7e53e96

Browse files
authored
Merge pull request #51 from code4tomorrow/kehao-ch13problems
Added Vector class
2 parents 6679744 + 2022320 commit 7e53e96

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
9+
def __init__(self, vals):
10+
self.vals = (
11+
vals # We're using the keyword self to create a field/property
12+
)
13+
print("Assigned values ", vals, " to vector.")
14+
15+
"""
16+
String Function
17+
18+
Converts the object to a string in readable format for programmers
19+
"""
20+
21+
def __str__(self):
22+
return str(self.vals) # Returns the contents of the vector
23+
24+
25+
vec = Vector([2, 3, 2])
26+
print(str(vec)) # [2, 3, 2]

0 commit comments

Comments
 (0)