关于Python 面向对象寻值的问题. How the number be found in the OOP in Python
今天在看Python面向对象的时候看到了一个很有意思的问题
Today. When i learning the OOP in python , I found a very interesting Question that how a number be found in the parent class and the child class .
First of all, let us define a class Animals
class Animals:
age = 0
Then let us define a child class
class Dog(Animals):
"Dog class"
next, we just create a main method :
zhang_san= Dog()
li_si = Dog()
zhang_san.age = 1
Dog.age = 10
print(zhang_san.age)
print(li_si.age)
We will get a result that the age in zhang_san is absolutely 1 .But how about the age in object li_si ?
Actually the result of li_si is 10.
So why ?
if we also set the value of age of li_si as any numbers such as 99
The outcome will be different.
So why ?
As the number of age is a class number , belong to the class of Animals and the dog is the child node of Animals
When you want to find a number in python . the program will to find the child node in first , if can not find any number you want the python will countine to search according to their parent nodes. At the end of the process , if it is still could not find a number , the program will throw error .
最新文章
- SQLServer比较两条数据是否相同
- HDFS副本存放策略
- springAOP实现基于注解的数据源动态切换
- finetuning caffe
- YY游戏私有云平台实践 (转自InfoQ )
- iOS UILocalNotification 每2周,每两个月提醒
- [麦先生]学习PDO循序渐进使用方式
- 使用JavaScript创建我的分页
- PhoneGap 在 Android 上的插件开发方法介绍
- 利用yum工具安装应用程序
- Oracle 关于事物的描述
- mysql常用操作(转自阿铭linux)
- Codeforces 700B Connecting Universities(树形DP)
- 【浏览器那些基础】Android平台有那些CPU类型
- adodb.RecordSet的属性和方法
- java中途强制跳出递归
- 小强HTML5手机发展之路(52)——jquerymobile触摸互动
- Promise同时进入catch和then——踩坑
- oracle- 数据表分区
- svn服务器的搭建备份和还原和svnmanager的使用
热门文章
- css之transform属性的使用
- 12月13日内容总结——路由分发、名称空间、虚拟环境、视图层三板斧、JsonResponse对象、request对象获取文件、视图层FBV与CBV的源码剖析、模版层简介
- you-get下载B站视频
- 通过Nacos配置刷新进行RabbitMQ消费者在线启停
- 视觉十四讲:第七讲_ORB特征点
- STM32F0库函数初始化系列:GPIO配置
- Cesium计算范围(十三)
- 我用ChatGPT做直播技术选型,卷死了同事
- 系统提权之:Unix 提权
- vue的数据更新视图不同步的处理用Vue.$set()