# 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. [luogu P1527]矩阵乘法(矩形k小)

    传送门 Description 给你一个N*N的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第K小数. Solution 整体二分 练习一波... 就是一堆询问放在一起二分 另外的,第一次发现原来矩 ...

  2. Spring Cloud Gateway(四):路由定义定位器 RouteDefinitionLocator

    本文基于 spring cloud gateway 2.0.1 1.简介 RouteDefinitionLocator 是路由定义定位器的顶级接口,它的主要作用就是读取路由的配置信息(org.spri ...

  3. 搭建vue-cli

    https://www.cnblogs.com/wisewrong/p/8570309.html https://www.jianshu.com/p/1ee1c410dc67

  4. 20175313 张黎仙《获奖感想与Java阶段性学习总结》

    一.获奖感想 很荣幸能够成为为数不多的小黄衫获得者之一,这是对我近一学期以来学习成果的肯定,也激励着我更加努力学习. 首先我要感谢的人就是娄嘉鹏老师.我曾在师生关系中提到,我认为的好老师的特点之一是: ...

  5. [Andorid] 通过JNI实现kernel与app进行spi通讯

    CPU:RK3399 系统:Android 7.1 人脸识别的要求越来越高,因此主板增加了 SE 加密芯片,加密芯片通过 spi 接口与 CPU 通讯. 对于 kernel 层的代码,Linux 原始 ...

  6. 网页表格导入导出Excel

    用JS实现网页表格数据导入导出excel. 首先是JS文件中的代码 (function($){ function getRows(target){ var state = $(target).data ...

  7. nginx中获取真实的客户端访问IP

    date : 2019-06-28 16:54:50 author: headsen chen notice: 个人原创 1,必需要先搞清楚的基本概念 1.1   什么是remote_addr     ...

  8. PorterDuffXfermode之PorterDuff.Mode.SRC_IN

    package com.loaderman.customviewdemo.view; import android.content.Context; import android.graphics.B ...

  9. ISO/IEC 9899:2011 条款6.2.7——兼容类型与组合类型

    6.2.7 兼容类型与组合类型 1.两个类型具有兼容类型,如果它们的类型是相同的.用于判定两个类型是否兼容的其它规则在6.7.2关于类型说明符中,6.7.3关于类型说明符中,6.7.6关于声明符中描述 ...

  10. (十六)集合框架(Collection和Map)和比较器(Comparable和comparator)

    一.集合框架 1.1 为什么要使用集合框架? 当我们需要保持一组一样(类型相同)的元素的时候,我们应该使用一个容器来保存,数组就是这样一个容器. 那么,数组的缺点是什么呢? 数组一旦定义,长度将不能再 ...