class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p = Person("Tom", 20)
class Animal:
def __init__(self, name):
self.name = name
def eat(self):
print("I can eat.")
class Dog(Animal):
def __init__(self, name):
super().__init__(name)
def bark(self):
print("I can bark.")
class Cat(Animal):
def __init__(self, name):
super().__init__(name)
def meow(self):
print("I can meow.")
d = Dog("Doggy")
d.eat() # 输出“I can eat.”
d.bark() # 输出“I can bark.”
c = Cat("Kitty")
c.eat() # 输出“I can eat.”
c.meow() # 输出“I can meow.”
def my_decorator(func):
def wrapper():
print("Before the function is called.")
func()
print("After the function is called.")
return wrapper
@my_decorator
def say_hello():
print("Hello World!")
say_hello()
arr = [(1, 2), (3, 4), (5, 6)] arr.sort(key=lambda x: x[0]) print(arr) # 输出[(1, 2), (3, 4), (5, 6)]
标签: Tkinter示例