面向对象
studA = {
"name":"yuhaohong",
"age":"23",
"birthday":"2017-03-17"
}
类
class 类名:
方法列表
- 定义一个类:
- ==在类中定义的方法,第一个参数都要写self==
class Dog:
def bark(self):
print('wang wang ~')
dog = Dog()
dog.bark()
dog = Dog()
dog.weight = 5
dog.color = 'yellow'
print(dog.weight)
class Cat:
def eat(self):
print('吃鱼')
self.weight += 1
cat = Cat()
cat.weight = 1o
cat.eat()
cat.weight += 5
print(cat.weight)
class Dog:
def __init__(slef):
self.weight = 5;
self.color='yellow'
class Cat:
def __init__(self,weight,color):
self.weight = weight
self.color = color
080808