关于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 .
关于Python 面向对象寻值的问题. How the number be found in the OOP in Python的更多相关文章
- python 面向对象学习
------Python面向对象初 下面写一个类的简单实用,以便方便理解类 #python 3.5环境,解释器在linux需要改变 #阅读手册查询readme文件 #作者:S12-陈金彭 class ...
- python—面向对象设计
一:三大编程范式 1.面向过程编程 2.函数式编程 3.面向对象编程 (类:把一类事物的相同的特征和动作整合到一起就是类,类是一个抽象的概念) (对象:就是基于类而创建的一个具体的事物 [具体存在的] ...
- Python面向对象05 /私有成员、类方法、静态方法、属性、isinstance/issubclass
Python面向对象05 /私有成员.类方法.静态方法.属性.isinstance/issubclass 目录 Python面向对象05 /私有成员.类方法.静态方法.属性.isinstance/is ...
- python 面向对象十一 super函数
python 面向对象十一 super函数 super函数用来解决钻石继承. 一.python的继承以及调用父类成员 父类: class Base(object): def __init__(se ...
- Python面向对象(上)
Python面向对象(上) python是一门面向对象的编程语言.何为对象?对象是类的实例.在生活中,任何一个事物都是一个对象,如牡丹花.牡丹花的类是花类,同样属于花类的还有荷花.月季花.金银花.菊花 ...
- python 面向对象初级篇
Python 面向对象(初级篇) 概述 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数进行分类和封装,让开发" ...
- Python 面向对象 基础
编程范式概述:面向过程 和 面向对象 以及函数式编程 面向过程:(Procedure Oriented)是一种以事件为中心的编程思想. 就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现 ...
- python面向对象进阶(八)
上一篇<Python 面向对象初级(七)>文章介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使 ...
- python 面向对象(进阶篇)
上一篇<Python 面向对象(初级篇)>文章介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使 ...
- python 面向对象编程学习
1. 问题:将所有代码放入一个py文件:无法维护 方案:如果将代码才分放到多个py文件,好处: 1. 同一个名字的变量互相不影响 2.易于维护 3.引用模块: import module 2.包:解决 ...
随机推荐
- MATLAB人工神经网络ANN代码
本文介绍基于MATLAB实现人工神经网络(ANN)回归的详细代码与操作. 目录 1 分解代码 1.1 循环准备 1.2 神经网络构建 1.3 数据处理 1.4 模型训练参数配置 1.5 神经网络实 ...
- 命令行部署repmgr管理集群+switchover+切换测试
本次部署未使用securecmd/kbha工具.无需普通用户到root用户的互信. 建立系统数据库安装用户组及用户,在所有的节点执行 root用户登陆服务器,创建用户组及用户并且设置密码 [root@ ...
- DNA
思路一: 这题需要桶+哈希(简化版像A 1 B 2 ......) 具体: 先把数据输入 再枚举可能的右端点,再由右端点得到左端点(l和r相差k) 在 l到r 区间内将这一段区间哈希成一个4进制数 ...
- FAS2720 配置
FAS 2720配置操作 第1章 初始化 1.1设备物理安装 1.1.1组件介绍 机头FAS 2720 (2U) 前面板 后面 1.1.2准备工作 (1)工具准备 螺丝刀.网线.Console线. ...
- 图解论文《The Part-Time Parliament》
本文以图文并茂的方式重新演绎 Paxos 开山之作 <The Part-Time Parliament>[1],并尝试解释原论文中语焉不详的地方. 背景 在 Paxos 小岛上,施行着一种 ...
- Art of Illusion 一款**的开源 3D 建模和渲染软件
原文地址:https://www.mvrlink.com/artofillusion/ Art of Illusion 是一个免费的开源 3D 建模和渲染工作室.它的许多功能可与商业程序中的功能相媲美 ...
- flutter系列之:Navigator的高级用法
目录 简介 named routes 给named route传参数 从Screen返回值 向Screen传值 总结 简介 上篇文章我们讲到了flutter中navigator的基本用法,我们可以使用 ...
- DIV 阴影
<div class="div">111</div> .div { width:200px; height:200px; box-shadow: 0 0 1 ...
- 通过 Blob 创建下载文件
Blob 如上图所示,Blob 对象有三个部分组成,data:image/jpeg 表示该 Blob 是什么类型的文件.base64 是一个二进制到文本的编码,更多细节查看Base64 编码/解码.其 ...
- Spring cloud Alibaba Nacos服务注册发现和配置中心
Nacos(官方网站:http://nacos.io)是一个易于使用的平台,旨在用于动态服务发现,配置和服务管理.它可以帮助您轻松构建云本机应用程序和微服务平台. Nacos = Eureka + c ...