今天在看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 .

最新文章

  1. SQLServer比较两条数据是否相同
  2. HDFS副本存放策略
  3. springAOP实现基于注解的数据源动态切换
  4. finetuning caffe
  5. YY游戏私有云平台实践 (转自InfoQ )
  6. iOS UILocalNotification 每2周,每两个月提醒
  7. [麦先生]学习PDO循序渐进使用方式
  8. 使用JavaScript创建我的分页
  9. PhoneGap 在 Android 上的插件开发方法介绍
  10. 利用yum工具安装应用程序
  11. Oracle 关于事物的描述
  12. mysql常用操作(转自阿铭linux)
  13. Codeforces 700B Connecting Universities(树形DP)
  14. 【浏览器那些基础】Android平台有那些CPU类型
  15. adodb.RecordSet的属性和方法
  16. java中途强制跳出递归
  17. 小强HTML5手机发展之路(52)——jquerymobile触摸互动
  18. Promise同时进入catch和then——踩坑
  19. oracle- 数据表分区
  20. svn服务器的搭建备份和还原和svnmanager的使用

热门文章

  1. css之transform属性的使用
  2. 12月13日内容总结——路由分发、名称空间、虚拟环境、视图层三板斧、JsonResponse对象、request对象获取文件、视图层FBV与CBV的源码剖析、模版层简介
  3. you-get下载B站视频
  4. 通过Nacos配置刷新进行RabbitMQ消费者在线启停
  5. 视觉十四讲:第七讲_ORB特征点
  6. STM32F0库函数初始化系列:GPIO配置
  7. Cesium计算范围(十三)
  8. 我用ChatGPT做直播技术选型,卷死了同事
  9. 系统提权之:Unix 提权
  10. vue的数据更新视图不同步的处理用Vue.$set()