We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6679744 commit 78ca7afCopy full SHA for 78ca7af
3_advanced/chapter13/examples/vector.py
@@ -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