20044031
2021-03-08 21:12
class Animal(object):
def_init_(self,name,age):
self.name = name
self.age = age
dog = Animal('Tim',4)
cat = Animal('Aim',5)
print(dog.name)
print(dog.age)
print(cat.name)
print(cat.age)
class Animal(): def __init__(self,name,age): self.name = name self.age = age print('{}今年{}岁'.format(name,age)) dog = Animal('汪汪',18) cat = Animal('喵喵',30)
class Animal(object): def __init__(self, name, age): self.name = name self.age = age dog = Animal('Tim', 4) cat = Animal('Aim', 5) print(dog.name) print(dog.age) print(cat.name) print(cat.age)
def后有个空格,init前后是两个下划线
Python3 进阶教程(新版)
41910 学习 · 236 问题
相似问题
回答 2
回答 2
回答 4
回答 1
回答 5