今天在看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的更多相关文章

  1. python 面向对象学习

    ------Python面向对象初 下面写一个类的简单实用,以便方便理解类 #python 3.5环境,解释器在linux需要改变 #阅读手册查询readme文件 #作者:S12-陈金彭 class ...

  2. python—面向对象设计

    一:三大编程范式 1.面向过程编程 2.函数式编程 3.面向对象编程 (类:把一类事物的相同的特征和动作整合到一起就是类,类是一个抽象的概念) (对象:就是基于类而创建的一个具体的事物 [具体存在的] ...

  3. Python面向对象05 /私有成员、类方法、静态方法、属性、isinstance/issubclass

    Python面向对象05 /私有成员.类方法.静态方法.属性.isinstance/issubclass 目录 Python面向对象05 /私有成员.类方法.静态方法.属性.isinstance/is ...

  4. python 面向对象十一 super函数

    python 面向对象十一 super函数   super函数用来解决钻石继承. 一.python的继承以及调用父类成员 父类: class Base(object): def __init__(se ...

  5. Python面向对象(上)

    Python面向对象(上) python是一门面向对象的编程语言.何为对象?对象是类的实例.在生活中,任何一个事物都是一个对象,如牡丹花.牡丹花的类是花类,同样属于花类的还有荷花.月季花.金银花.菊花 ...

  6. python 面向对象初级篇

    Python 面向对象(初级篇) 概述 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数进行分类和封装,让开发" ...

  7. Python 面向对象 基础

    编程范式概述:面向过程 和 面向对象 以及函数式编程 面向过程:(Procedure Oriented)是一种以事件为中心的编程思想. 就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现 ...

  8. python面向对象进阶(八)

    上一篇<Python 面向对象初级(七)>文章介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使 ...

  9. python 面向对象(进阶篇)

    上一篇<Python 面向对象(初级篇)>文章介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使 ...

  10. python 面向对象编程学习

    1. 问题:将所有代码放入一个py文件:无法维护 方案:如果将代码才分放到多个py文件,好处: 1. 同一个名字的变量互相不影响 2.易于维护 3.引用模块: import module 2.包:解决 ...

随机推荐

  1. 【随笔记】NDK 编译开源库 SQLite3

    NDK 编译环境搭建请参考:[工作笔记]NDK 编译开源库 nghttp2/openssl/curl_lovemengx的博客-CSDN博客 一.下载源代码 wget https://github.c ...

  2. 【随笔记】XR872 Codec 驱动移植和应用程序实例(附芯片调试方法)

    XR872 的 SDK 是我目前接触过那么多款 MCU 的 SDK 中,唯一一个将框架和 RTOS 结合的非常完美的 SDK .无论是代码风格还是框架的设计,看起来都很赏心悦目,而且是源码开源.希望能 ...

  3. 构建api gateway之 动态插件

    动态插件 之前已经拆解细点逐个介绍了 tcp .http 代理相关核心点,现在介绍一个让 api gateway 变得很灵活的功能实现: 动态插件. 由于 lua 的动态语言特点,我们可以比较方便做到 ...

  4. @Slf4j -- lombok.extern.slf4j.Slf4j;

    @Log4j:注解在类上:为类提供一个 属性名为log 的 log4j 日志对像 package com.atguigu.springcloud.controller; import com.atgu ...

  5. app实现外部浏览器打开链接

    需求:安卓和IOS开发的混合app.前端使用vue,vant2,安卓使用java,ios使用的object-c.实现效果:点击按钮,下载PDF附件,app跳转到手机外部浏览器,下载附件...... 1 ...

  6. Java ”框架 = 注解 + 反射 + 设计模式“ 之 注解详解

    Java "框架 = 注解 + 反射 + 设计模式" 之 注解详解 每博一文案 刹那间我真想令时光停住,好让我回顾自己,回顾失去的年华,缅怀哪个穿一身短小的连衣裙 和瘦窄的短衫的小 ...

  7. Python GDAL读取栅格数据并基于质量评估波段QA对指定数据加以筛选掩膜

      本文介绍基于Python语言中gdal模块,对遥感影像数据进行栅格读取与计算,同时基于QA波段对像元加以筛选.掩膜的操作.   本文所要实现的需求具体为:现有自行计算的全球叶面积指数(LAI).t ...

  8. JZOJ 3432. 【GDOI2014模拟】服务器

    题目 解析 很容易想到的 \(dp\): 设 \(f_i\) 表示已经处理完 \(1..i\) 并且 \(i\) 是直接复制的需要的最小花费 那么 \(f_i=f_j+(i-j) \times (i- ...

  9. C#泛型接口请求封装类

    using HttpUtil; using Newtonsoft.Json; using System; using System.Collections.Generic; using System. ...

  10. JS 获取参数、封装

    var common = { getQueryString : function(name){ var reg = new RegExp('(^|&)' + name + '=([^& ...