1、Python中类的学习
2021/11/19 11:11:33
本文主要是介绍1、Python中类的学习,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
class student: #定义类 student_count=0 #定义类变量 def __init__(self, name, age): #类的初始化 self.name = name self.age = age student.student_count += 1 def dis_student(self): #定义类的实例 print("student name is "+self.name,'student_age is '+self.age) student1 = student('zhang', '25') student2 = student('chen', '36') student1.dis_student() student2.dis_student() print(student.student_count)
#子类 父类的定义 class people: def __init__(self, name, age): self.name = name self.age = age def dis_name(self): print('her name is ', self.name) def dis_age(self): print('her age is ', self.age) class student(people): def __init__(self,name,age,school): self.name = name self.age = age self.school = school def dis_school(self): print('her school is ',self.school) Student=student('zhang','23','wcxx') Student.dis_age() Student.dis_name() Student.dis_school()
这篇关于1、Python中类的学习的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门
- 2024-12-24Python编程基础:变量与数据类型
- 2024-12-23使用python部署一个usdt合约,部署自己的usdt稳定币
- 2024-12-20Python编程入门指南
- 2024-12-20Python编程基础与进阶
- 2024-12-19Python基础编程教程
- 2024-12-19python 文件的后缀名是什么 怎么运行一个python文件?-icode9专业技术文章分享
- 2024-12-19使用python 把docx转为pdf文件有哪些方法?-icode9专业技术文章分享
- 2024-12-19python怎么更换换pip的源镜像?-icode9专业技术文章分享