Code:
class Dog:
def bark(self):
print("Woof")
foo = Dog()
# Override bark with a new function in the same line
foo.bark = lambda self: print("Woof Woof")
# New bark: "Woof Woof"
foo.bark()
Code:
class Dog:
def bark(self):
print("Woof")
foo = Dog()
# Override bark with a new function in the same line
foo.bark = lambda self: print("Woof Woof")
# New bark: "Woof Woof"
foo.bark()