# 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. 前端逼死强迫症之DOM

    Dom:document.相当于把所有的html文件,转换成了文档对象. 之前说过:html-裸体的人:css-穿上衣服:js-让人动起来. 让人动起来,就得先找到他,再修改它内容或属性. 找到标签 ...

  2. zabbix (6) 为主机添加监控项,触发器,动作

    先了解一下zabbix的相关概念 监控项(iterms):一个具体的指标,比如某个人的体重. 键(key):通过定义(自定义或者zabbix自带)的key获取相应指标的具体值,比如这个人的体重50斤 ...

  3. java之map遍历

    java开发中常常会用到遍历,所以下边就列举四种map的遍历方法. public class testMap { public static void main(String[] args) { Ma ...

  4. 详谈mysqldump数据导出的问题

    1,使用mysqldump时报错(1064),这个是因为mysqldump版本太低与当前数据库版本不一致导致的. mysqldump: Couldn't execute 'SET OPTION SQL ...

  5. PHP中定义常量的区别,define() 与 const

      正文 在PHP5.3中,有两种方法可以定义常量: 使用const关键字 使用define()方法 const FOO = 'BAR'; define('FOO','BAR'); 这两种方式的根本区 ...

  6. JAVA_SWT 事件的四种写法

    一:匿名内部类写法 在一个组件下加入以下语句 text.addMouseListener(new MouseAdapter(){ public void mouseDoubleClich(MouseE ...

  7. List三个子类的特点

    List的三个子类的特点 ArrayList: 底层数据结构是数组,查询快,增删慢. 线程不安全,效率高. Vector: 底层数据结构是数组,查询快,增删慢. 线程安全,效率低. Vector相对A ...

  8. ARM 之一 ELF文件、镜像(Image)文件、可执行文件、对象文件 详解

    [转]https://blog.csdn.net/ZCShouCSDN/article/details/100048461 ELF 文件规范   ELF(Executable and Linking ...

  9. 40 Flutter仿京东商城项目签名验证原理、签名验证算法

    加群452892873 下载对应40课文件,运行方法,建好项目,直接替换lib目录 pubspec.yaml crypto: ^ SignServices.dart import 'dart:conv ...

  10. Delphi ADOQuery的速度优化

    今天终于把纠缠了几天的问题改完了,说到底只是一个很小的问题,就是ADOQuery的一个小属性. 把控件DBGridEh的一列的checkbox设为true,将其绑定DataSource和ADOQuer ...