Question | Click to View Answer |
What does the following code print to the console? class Person:
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
def full_name(self):
return f"{self.first_name} {self.last_name}"
gaga = Person("lady", "gaga")
print(gaga.full_name())
|
The |
What does the following code print to the console? class Mustache:
def __init__(self, color):
self.color = color
b = Mustache("brown")
print(b.color)
|
The |
What does the following code print to the console? class City:
def __init__(self, country, state):
self.country = country
self.state = state
houston = City("USA")
print(houston.country)
|
This code raises a TypeError with the following message: init() missing 1 required positional argument: 'state'. The houston = City("USA", "Texas")
|
What does the following code print to the console? class Dancer:
def __init__(self, height, country="Cuba"):
self.height = height
self.country = country
salsa_pro = Dancer(183)
print(salsa_pro.country)
|
The |
What does the following code print to the console? class Chair:
def __init__(self, material="wood"):
self.material = material
my_chair = Chair("plastic")
print(my_chair.material)
|
The default variable for the |
What does the following code print to the console? class Seatbelt:
def __init__(self, color):
self.color = color
my_seatbelt = Seatbelt("black")
my_seatbelt.color = "pink"
print(my_seatbelt.color)
|
Dot notation is used to update the |
What does the following code print to the console? class Beach:
def description():
return "sandy and wet"
print(Beach.description())
|
When methods don't have |
What does the following code print to the console? class Red:
def feeling():
return "Lucky!"
r = Red()
print(r.feeling())
|
This code raises a TypeError with the following message: feeling() takes 0 positional arguments but 1 was given. The feeling method can be edited to include Alternatively, the class Red:
def feeling():
return "Lucky!"
print(Red.feeling())
|
What does the following code print to the console? class Horrible:
def bad_code(weird):
return "Don't write code like this"
h = Horrible()
print(h.bad_code())
|
This code works, but it's not pretty. Instead of using In practice, you should always call this variable |