# Python继承
class Person(object):
"""人""" def __init__(self, name, age):
self._name = name
self._age = age @property
def name(self):
return self._name @property
def age(self):
return self._age @age.setter
def age(self, age):
self._age = age def play(self):
print('%s正在愉快的玩耍.' % self._name) def watch_av(self):
if self._age >= 18:
print('%s正在观看动作片.' % self._name)
else:
print('%s只能观看《熊出没》.' % self._name) class Student(Person):
"""学生""" def __init__(self, name, age, grade):
super().__init__(name, age)
self._grade = grade @property
def grade(self):
return self._grade @grade.setter
def grade(self, grade):
self._grade = grade def study(self, course):
print('%s的%s正在学习%s.' % (self._grade, self._name, course)) class Teacher(Person):
"""老师""" def __init__(self, name, age, title):
super().__init__(name, age)
self._title = title @property
def title(self):
return self._title @title.setter
def title(self, title):
self._title = title def teach(self, course):
print('%s%s正在讲%s.' % (self._name, self._title, course)) def main():
stu = Student('王二小', 15, '初三')
stu.study('数学')
stu.watch_av()
t = Teacher('Anthony', 38, '老叫兽')
t.teach('Python程序设计')
t.watch_av() if __name__ == '__main__':
main()

Python class and object的更多相关文章

  1. Debug 路漫漫-11:Python: TypeError: 'generator' object is not subscriptable

    调试程序,出现以下错误: Python: TypeError: 'generator' object is not subscriptable “在Python中,这种一边循环一边计算的机制,称为生成 ...

  2. python pip 'nonetype' object has no attribute 'bytes'

    python pip 'nonetype' object has no attribute 'bytes' 更新 pip for Windows : python -m pip install -U ...

  3. python everything is object

    python面向对象非常彻底,即使过程式的代码风格,python在运作的时候也是面向对象的.everything is object. 差异 在面向对象的理念上,python和非常工程化的面向对象语言 ...

  4. Python TypeError: 'module' object is not callable 原因分析

    今天尝试使用pprint进行输出,语句为 >>>import pprint >>>pprint(people) 结果报错,TypeError: 'module' o ...

  5. Python 中的object takes no parameters错误

    Python是一门面向对象的语言,中我们首先创建一个类: class Student(object): def _init_(self,name,score): self.name = name se ...

  6. 【Python深入】Python中继承object和不继承object的区别

    python中定义class的时候,有object和没有object的不同?例如: class Solution(object): class Solution(): 这俩的区别在于—————— 在p ...

  7. python: "TypeError: 'type' object is not subscriptable"

    目前stackoverflow找到两种情况的解决办法: 1.TypeError: 'type' object is not subscriptable when indexing in to a di ...

  8. Python: TypeError: 'dict' object is not callable

    问题:  TypeError: 'dict' object is not callable 原因:  dict()是python的一个内建函数,如果将dict自定义为一个python字典,在之后想调用 ...

  9. python 中的object与type的关系

    object 和 type的关系很像鸡和蛋的关系,先有object还是先有type没法说,obejct和type是共生的关系,必须同时出现的. 在看下去之前,也要请先明白,在Python里面,所有的东 ...

  10. 【Python】unicode' object is not callable

    在Python中,出现'unicode' object is not callable的错误一般是把字符串当做函数使用了.

随机推荐

  1. [线性代数] 线性子空间入門 Basic Vector Subspaces

    导语:其他集数可在[线性代数]标籤文章找到.线性子空间是一个大课题,这里先提供一个简单的入门,承接先前关于矩阵代数的讨论,期待与你的交流. Overview: Subspace definition ...

  2. Hadoop hadoop的介绍和几种模式

    Hadoop简介 Hadoop软件库是一个开源框架,允许使用简单的编程模型跨计算机集群分布式处理大型数据集.它旨在从单个服务器扩展到数千台计算机,每台计算机都提供本地计算和存储.库本身不是依靠硬件来提 ...

  3. Invalid Component definition:header

    主要是header不是字符串,而是变量

  4. ES6---修饰器

    类的修饰 许多面向对象的语言都有修饰器(Decorator)函数,用来修改类的行为.目前,有一个提案将这项功能,引入了 ECMAScript. @testable class MyTestableCl ...

  5. Java核心复习——J.U.C ArrayBlockingQueue源码分析

    介绍 依赖关系 源码 构造方法 public ArrayBlockingQueue(int capacity) { this(capacity, false);//默认构造非公平的有界队列 } pub ...

  6. XGBoost、LightGBM、Catboost总结

    sklearn集成方法 bagging 常见变体(按照样本采样方式的不同划分) Pasting:直接从样本集里随机抽取的到训练样本子集 Bagging:自助采样(有放回的抽样)得到训练子集 Rando ...

  7. Python 自学笔记(七)

    1.定义函数和调用函数 1-1.定义函数 定义函数的语法书写:def 函数名(参数名)(注:括号内可以为空,也可以为多个参数,多个参数间用逗号隔开即可) 由上可以看出,函数默认返回None 2.函数的 ...

  8. matlab将多张图片合成视频

    文件夹内多张图合成为视频: route='D:\文件及下载相关\桌面\**\Matlab_code\result';%基本路径 %d=dir([route '\*.bmp']);%.jpg格式 Wri ...

  9. Java开发中使用sort排序

    Java开发中使用sort排序 BaiduSpring https://baijiahao.baidu.com/s?id=1625440912158830354&wfr=spider& ...

  10. 20Flutter通过TabController定义顶部tab切换,介绍生命周期函数

    基本使用: import 'package:flutter/material.dart'; class TabBarControllerPage extends StatefulWidget { Ta ...