关于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.包:解决 ...
随机推荐
- python自动发布-优化版本
import sys import time import os import paramiko from pygments.lexers import shell baseconfig = { &q ...
- BIO和NIO的基本用法和API讲解
1 BIO 可以理解为Blocking IO 是同步阻塞的IO,也就是说,当有多个请求过来的时候,请求会呈现为链状结构,遵循先进先出的原则 1.1 单线程版本 1.1.1 服务端 //服务端单线程处理 ...
- Vue35 路由
1 简介 vue-router是vue的一个插件,专门用来实现SPA应用.SPA也就是单页Web应用,特点是:整个应用只有一个完整的页面,点击页面中的导航链接不会刷新页面,只会做页面的局部更新,数据需 ...
- FPS 逆向 CS.起源 绘制 教程(下周完成笔记)
1.找到人物坐标X YZ2.找到鼠标X Y3.易语言读取人物坐标4.读取敌人坐标打开控制台服务器与客户端尽量找客户端 找到XYZ5.实时读取敌人坐标6.三角函数转换屏幕坐标FOV 视场角狙击枪找FOV ...
- 快速删除 node_modules
node_modules 文件夹很大,不推荐右键通过回收站删除,通过 rimraf 来删除速度很快: # 安装 rimraf npm i -g rimraf # 删除 node_modules rim ...
- 【必看】RuoYiVuek框架-数据源动态新增、配置如此简单!
应用场景 系统用户只能访问系统配置的数据源(可动态新增修改的) RuoYi Vue 框架源码 点我跳转 实现方式 1.系统提供 Yml文件配置 + Druid加载数据源 + @DataSource注解 ...
- net core 依赖注入DI
控制反转:Inversion Of Control,简称 IOC,是面向对象中的一种设计原则,调用者不自己new实例,而是交给容器去创建,可以减轻代码的耦合度. 依赖注入:Dependency Inj ...
- LeetCode-2104 子数组范围和
来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/sum-of-subarray-ranges 题目描述 给你一个整数数组 nums .nums 中 ...
- shell 命令小记
if [ -d /abc ] if与后面括号要有空格 中括号与内部的变量也要有空格 for header in `ls *.h` do cp $header /usr/include/mymuduo ...
- fastai fit_one_cycle AttributeError: 'function' object has no attribute 'parameters'
初学fastai fit_one_cycle语句报错指向614行, 即: return [p for p in m.parameters() if p.requires_grad] 在以前遇到这种 ...