python类
#!/usr/bin/python #coding=utf-8 #好好学习,天天向上 class Dog: """一次模拟小狗的简单尝试""" def __init__(self,name,age): """初始化属性名字和年龄""" self.name = name self.age = age def sit(self): """模拟小狗蹲下""" print(f"{self.name} is now sitting.") def roll_over(self): """模拟小狗打滚""" print(f"{self.name} rolled over!") my_dog = Dog('tim',6) my_dog.sit() my_dog.roll_over() print(f"my dog name is {my_dog.name} and age is {my_dog.age} years old")