Lecture Materials

Questions & Answers

Q: how are we doing on this friday!

A1:  Question is, how are you?! :)

Q: Great! How are you!

A1:  Doing great :)

Q: I'm a grad student, graduating this quarter on June 14. Will you have enought time to grade the last assignment, which is due on June 10, and process my grades?

A1:  Yep, we’re aware of all grading deadlines

Q: Do we have any more AMAs this quarter? :) Wasn’t able to attend prior ones but hopefully there’s still more

A1:  None are planned, but we’ll see if we can organize another

Q: Is ticket number a new variable? Why it is not defined?

A1:  every counter has a ticket_number variable!

A2:  It’s defined in the __init__ function!

Q: is count.next_value pre defined?

A1:  next value() is a function in the Counter class

Q: is count.next_value a written function in python?

A1:  next value() is a function in the Counter class

Q: is there a way to define the oop function so that we can write like count1.count_two_times(), not count_two_times(count1)?

A1:  Yes, you’d need to define it as a method in the Counter class as opposed to a function outside the class

Q: are count 1 and count 2 random variables? or did you set them both to 1?

A1:  Both of them are of type Counter, which starts counting from 1

Q: Is mutable analogous to a link?

A1:  No, mutable means that the thing at the end of the link can be changed

Q: How does python know what next.value() means?

A1:  It’s a method defined in the Counter class

Q: I see that he imported the Class, but who created this class? Was that done in another file?

A1:  He did - the Counter class is defined in counter.py

Q: what does the .nextvalue() do? Or is it just written to clarify what is happening?

A1:  It’s calling the next_value function in the Counter class

Q: So, you can have as many counts as you want, and also keep the track off each of them, right?

A1:  Yep!

Q: So are objects like links where we don’t have to return it in order for the changes to be saved?

A1:  Well, everything is a link, but an object is mutable, which is why you don’t need to return it

Q: To change an object, can you only use a method defined in the class?

A1:  No, but that’s the most common way of doing it

Q: that “value” can be whatever or something that must be in the object?

A1:  It’s just like a normal variable declaration, but the value should be something reasonable for that class

Q: .next_value() is already a python command, right?

A1:  No - it’s a function in the Counter class

Q: What if in the constructor I defined more than one object like, self.val1 = 0 and self.val2 = 0. Then when in def main(): I call count1 = Counter which self.val is stored in count1?

A1:  Both count1 and count2 would have separate val1 and val2 instance variables

Q: How is this different than just passing count1 into next_value as a parameter and then returning the += value?

A1:  The class keeps track of count1 for you - in this case, there isn’t a huge value add but for more complex objects this is instrumental

Q: Does this mean the self paramater is how some of the built-in functions we were working w/, e.g. list.strip() knows to call on list in order to modify the list?

A1:  Yes, exactly!

Q: What is the difference between an instance variable and an object?

A1:  Objects comprise of instance variables

Q: Similar the Image reference handout, can you guys create a lists, dictionaries and tuples hand out? And an objects and class hand out?

A1:  Lists, Dictionaries and Tuples are in the python reader - we’ll try to make one about objects and classes

Q: Since the class is Student, and name, ID, and units are instance variables, what is the object?

A1:  If—in another program—you say s = Student(), s is an object!

Q: Can objects only do functions we specify as a methods?

A1:  Those are the only ones you can call with noun.verb() syntax

Q: Where and when will the class and object coding be useful? I am kind of confuded how to apply them...

A1:  live answered

A2:  How would you write a program with 10 bouncing balls (recall when we did 1 bouncing ball)

Q: So objects have instance variables that describe the object?

A1:  live answered

Q: what happens when methods aren’t reflexive, is that ok?

A1:  live answered

Q: Any burrito place recommendations for when the quarantine is over?

A1:  live answered

Q: How do you know what variables a counter have? One has to pass that information from data or how does it work?

A1:  live answered