Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1def __str__(self): return 42 | AOutput: 3.14 | |
| 2def Str(self): | BOk: Returns a formatted string from __str__ | |
| 3def __str__(self): | CValid: Defines string representation of an object | |
| 4return f'Dog: {self.name}' | DOutput: [1, 2] | |
| 5str(3.14) | EError: __str__ must return a string | |
| 6str([1, 2]) | FError: Magic method must be __str__ |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
__str__(self) — Returns a human-readable string used by print() and str().~~__repr__(self)class Dog:
def __str__(self):
return 'Dog: ' + self.nameclass Dog:
def __str__(self):
return self.nameclass Dog:
def __str__(self):
return 'Dog: ' + self.namedog = Dog('Rex')
print(dog)class Point:
def __str__(self):
return '(' + str(self.x) + ')'