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.
2 parents 6679744 + 2022320 commit 7e53e96Copy full SHA for 7e53e96
3_advanced/chapter13/examples/vector.py
@@ -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