Complete the code to define an instance method that prints the name.
class Person: def __init__(self, name): self.name = name def show_name(self): print(self.[1])
The instance method accesses the instance variable name using self.name.
Complete the code to define a class method that prints the class name.
class Person: @classmethod def show_class(cls): print(cls.[1])
__class__ which is not an attribute of cls.__name__ which is a module attribute.The class method uses cls.__qualname__ to get the class's qualified name.
Fix the error in the static method that returns a greeting string.
class Person: @staticmethod def greet(): return 'Hello, ' + [1]
Static methods do not receive self or cls, so use a fixed string like 'World'.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if [2]
The dictionary comprehension uses len(word) for values and filters words with length greater than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is less than 6.
words = ['apple', 'bat', 'carrot', 'dog'] result = [1]: [2] for word in words if [3]
word.lower() instead of uppercase.The comprehension maps uppercase words to their lengths, filtering words shorter than 6 characters.