面向对象的编程
2021/11/11 1:10:04
本文主要是介绍面向对象的编程,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
初阶:
#面向对象的特征:封装,继承,多态 #初阶 class dog: def __init__(self,name): self.name = name def bulk(self): print("%s:wangwangwang!"%self.name) d1 = dog("vergil") d2 = dog("tanying") d1.bulk() d2.bulk() #进阶 class role(object): def __init__(self,name,sex,age,job,money = 10000): self.name = name self.sex = sex self.age = age self.job = job self.money = money def buy(self,something): print("%s has bought a %s"%(self.name,something)) print("%s has %s in his hand"%(self.name,self.money)) def growth(self,newage): print("%s has growth from %s to %s"%(self.name,self.age,newage)) def overview(self,high): print("%s is a %s,and he is %s high"%(self.name,self.sex,high)) def drump(self,newjob): print("%s has changed job from %s to %s"%(self.name,self.job,newjob)) vergil = role("vergil","male",25,"IT") vergil.buy("cake") vergil.growth(26) vergil.overview(175) vergil.drump("Financial software test")
这篇关于面向对象的编程的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-04百万架构师第六课:设计模式:策略模式及模板模式
- 2025-01-04百万架构师第七课:设计模式:装饰器模式及观察者模式
- 2025-01-04适用于企业管理的协作工具API推荐
- 2025-01-04挑战16:被限流的CPU
- 2025-01-03企业在选择工具时,如何评估其背后的技术团队
- 2025-01-03Angular中打造动态多彩标签组件的方法
- 2025-01-03Flask过时了吗?FastAPI才是未来?
- 2025-01-0311个每位开发者都应知道的免费实用网站
- 2025-01-03从REST到GraphQL:为什么以及我是如何完成转型的
- 2025-01-03掌握RAG:从单次问答到连续对话