class Student: def __init__(self, sid,name,height,sex): self.sid=sid self.name=name self.height=height self.sex=sex def print(): 补充代码,打印本同学的全部信息
时间: 2023-06-17 08:02:14 浏览: 125
python基础进阶1.6:面向对象之类,对象及__init__(),self相关用法讲解
class Student:
def __init__(self, sid, name, height, sex):
self.sid = sid
self.name = name
self.height = height
self.sex = sex
def print_info(self):
print("学号:", self.sid)
print("姓名:", self.name)
print("身高:", self.height)
print("性别:", self.sex)
# 调用示例
s = Student("20210001", "张三", 175, "男")
s.print_info() # 输出该学生的全部信息
阅读全文