File tree Expand file tree Collapse file tree 1 file changed +18
-15
lines changed
3_advanced/chapter13/examples Expand file tree Collapse file tree 1 file changed +18
-15
lines changed Original file line number Diff line number Diff line change 11class 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- """
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 = vals # Notice! We are using the keyword self to create a field or property (for Javascript users)
11+ print ("Assigned values " , vals , " to vector." )
12+
13+ """
1314 String Function
1415
1516 Converts the object to a string in readable format for programmers
1617 """
17- def __str__ (self ):
18- return str (self .vals ) # Returns the contents of the vector
19-
18+
19+ def __str__ (self ):
20+ return str (self .vals ) # Returns the contents of the vector
21+
22+
2023vec = Vector ([2 , 3 , 2 ])
21- print (str (vec )) # [2, 3, 2]
24+ print (str (vec )) # [2, 3, 2]
You can’t perform that action at this time.
0 commit comments