python--基础--简单的方法和类
def MyMessage(name,age,where): print( "My name is :" +name.upper()+","+ "this yesr is :" +str(age)+" year old!"+ "come from :"+where+"." ) MyMessage("zhenghanqiao",3000,"guangxi") class Dog(): def __init__(self, name, age): self.name = name self.age = age def sit(self): print(self.name.title() + " is now sitting.") def roll_over(self): print(self.name.title() + " rolled over!") dog = Dog("zhenghanqiao", 18) print("My name is" + dog.name + "this yesr" + str(dog.age) + "old!") dog.sit() dog.roll_over()