1,第1关 学习-Python面向对象之属性
class Dog: # 创建类
def __init__(self, name, age): # 建立构造方法,里面的参数可以接收实例化的时候传过来的参数
self.name = name # 接收参数
self.age = age # 接收参数
name = str(input()) # 输入名字为字符型
age = int(input()) # 输入年龄为整形
d = Dog(name, age) # 创建对象,实例化类
print("Dog %s的年龄为%d岁" % (d.name, d.age)) # 输出对象属性
2,第1关 学习-Python面向对象之类的定义和使用
class Animal:
foot = 4
weight = 14
height = 30
# 请在下面的Begin-End之间按照注释中给出的提示编写正确的代码
########## Begin ##########
# 第1步:实例化类
animal = Animal()
# 第2步:输出三个类属性的值
print("foot属性值为:%d" % animal.foot)
print("