Within the __init__ method, the new object should be returned with what code?

Practice More Questions From: Quiz 6a / Quiz 6b

Q:

Every class definition should include an initializer method. What is the name of the initializer method? Refer to the first object-oriented programming video.Note: While you can get away with not having an initializer method, doing so almost always implies using techniques beyond the scope of this course or bad program design. So, beginners should always define an initializer method.

Q:

In Python, what is the main difference between a function and a method?

Q:

As an example class, consider the following code from one of the videos: class Character: def __init__(self, name, initial_health): self.name = name self.health = initial_health self.inventory = [] def __str__(self): s = “Name: ” + self.name s += ” Health: ” + str(self.health) s += ” Inventory: ” + str(self.inventory) return s def grab(self, item): self.inventory.append(item) def get_health(self): return self.healthWhat does the self parameter represent?

Q:

A common feature in many object-oriented languages is method overloading. In this quiz question, you will learn by example what overloading is and whether or not Python supports it. Turn the following English description into code. Start a class definition. We’ll call the class \color{red}{\verb|Overload|}Overload. Define an init method. Along with the standard self it has one parameter. The method does nothing useful for this example — use the Python do-nothing statement pass for the body. Define a second $$$$ method. Along with $$$$ it has two parameters. This method also does nothing useful.Outside of the class, we want to create two Overload objects. If Python supports overloading, you will be able to create an Overload object with one argument, and create another Overload object with two arguments. Does Python support overloading?

Q:

What is the position of the center of the top-left card (Ace of Clubs, A♣) in the tiled image discussed in the “Tiled images” video? Remember that each card in this tiled image has size 73 x 98 pixels. (Note that the tiled image used in the current version of your Blackjack mini-project is slightly smaller.)

Q:

When using Dropbox to store images for use with CodeSkulptor, what should the www portion of the DropBox URL be replaced by? Refer to the video on tiled images.

Q:

Within the __init__ method, the new object should be returned with what code?

Q:

One way of understanding code is to think about other code that accomplishes the same thing — i.e., given the same starting values, it returns and/or mutates the same values. This following defines one way to concatenate multiple lists. For example, list_extend_many([[1,2], [3], [4, 5, 6], [7]]) returns [1, 2, 3, 4, 5, 6, 7] and doesn’t mutate anything.def list_extend_many(lists): “””Returns a list that is the concatenation of all the lists in the given list-of-lists.””” result = [] for l in lists: result.extend(l) return resultWhich of the following definitions are equivalent? I.e., which always produce the same output for the same input, and never mutate the input or any global variable?

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments