Complete the code to define a static method inside a class.
class Calculator: @staticmethod def add(a, b): return a [1] b
The add method should return the sum of a and b, so the operator is +.
Complete the code to define a class method that returns the class name.
class Person: @classmethod def get_class_name(cls): return cls.[1]
The __qualname__ attribute of a class gives its qualified name, which is useful in class methods.
Fix the error in the instance method that returns the full name.
class User: def __init__(self, first, last): self.first = first self.last = last def full_name([1]): return f"{self.first} {self.last}"
cls or other names instead of self.Instance methods must have self as the first parameter to access instance attributes.
Fill both blanks to create a class method that creates an instance from a string.
class Book: def __init__(self, title, author): self.title = title self.author = author @classmethod def from_string(cls, book_str): title, author = book_str.split([1]) return cls([2], author)
The string is split by a comma and space ", ". The first part is assigned to title which is passed to the constructor.
Fill all three blanks to create a static method that checks if a number is even.
class NumberUtils: @staticmethod def is_even([1]): return [2] % [3] == 0
The static method takes a number num and returns True if it is divisible by 2 (even).