# 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. 走进JavaWeb技术世界14:通过项目逐步深入了解Mybatis(一)

    通过项目逐步深入了解Mybatis(一) 2017-06-12 文章导航 Mybatis 和 SpringMVC 通过订单商品案例驱动 官方中文地址:http://www.mybatis.org/my ...

  2. 实现一个简单的Tomcat

    实现一个简单的Tomcat 1. Tomcat作用 我们的web应用会运行在Tomcat中,那么显然请求必定是先到达Tomcat的,Tomcat对于请求实际上会进行如下的处理: 提供Socket服务: ...

  3. Postgresql使用coalesce实现类似oracle的NVL方法

    COALESCE (expression_1, expression_2, ...,expression_n)依次参考各参数表达式,遇到非null值即停止并返回该值. 如果所有的表达式都是空值,最终将 ...

  4. linux tcp 高并发最大连接数

    Linux下高并发socket最大连接数所受的限制问题 1.修改用户进程可打开文件数限制 在Linux平台上,无论编写客户端程序还是服务端程序,在进行高并发TCP连接处理时,最高的并发数量都要受到系统 ...

  5. 上传图片获取base64编码、本地预览

    一.读取文件的对象 — new FileReader()   上传图片接口参数有图片base64编码(数组, imgBase64List ),主要用到 读取文件的对象 [ new FileReader ...

  6. IDEA启动tomcat报错:java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext、ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component

    先看错误日志: -May- ::.M26 -May- :: :: UTC -May- ::29.845 信息 [main] org.apache.catalina.startup.VersionLog ...

  7. matlab学习——02整数规划(蒙特卡洛法,指派问题,混合整数规划)

    02整数规划 蒙特卡洛法(随机取样法) 编写文件mengte.m,目标函数f和约束向量g function[f,g]=mengte(x); f=x(1)^2+x(2)^2+3*x(3)^2+4*x(4 ...

  8. thymeleaf自定义属性

    例如我想给添加一个属性data-page,可以根据(SpringEL/Ognl)表达式计算获得. 需求: 期望效果 app个数大于0,有数据时链接 <xxx data-page="/a ...

  9. [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/nginx/conf/nginx.conf:1

    带有sudo 权限执行就可以了

  10. MYSQL 启动问题

    1.日志中出现  [ERROR] InnoDB: The Auto-extending innodb_system data file './ibdata1' is of a different si ...