记录Python类与继承的一个错误
今天在学python的类与继承的时候遇到一个错误,原来是自己在ctrl+c ctrl+v的时候漏了一个括号
class Car():
def __init__(self,make,year,model):
self.make=make
self.model=model
self.year=year
self.odometer_reading=0
def get_descriptive_name(self):
long_name=str(self.year)+" "+self.make+" "+self.model
return long_name.title()
def read_odometer(self):
print("This car has "+str(self.odometer_reading)+"miles on it") def update_odometer(self,mileage):
if mileage>=self.odometer_reading:
self.odometer_reading=mileage
else:
print("You can't roll back an odometer")
def increment_odometer(self,miles):
self.odometer_reading+=miles
class ElectricCar(Car):
def __init__(self,make,model,year):
super.__init__(make,year,model)
my_tesla=ElectricCar('tesla','model s',2016)
print(my_tesla.get_descriptive_name())
运行时出现了以下的错误
super.__init__(make,year,model)
TypeError: descriptor '__init__' requires a 'super' object but received a 'str'
原来是22行的super()那里少了一个括号。
记录Python类与继承的一个错误的更多相关文章
- 孤荷凌寒自学python第二十二天python类的继承
孤荷凌寒自学python第二十二天python类的继承 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) python中定义的类可以继承自其它类,所谓继承的概念,我的理解 是,就是一个类B继承自 ...
- Python类的继承(进阶5)
转载请标明出处: http://www.cnblogs.com/why168888/p/6411918.html 本文出自:[Edwin博客园] Python类的继承(进阶5) 1. python中什 ...
- python 类定义 继承
0 前言 系统:win7 64bit IDE : python(x,y) 2.7.6.1 IDE集成的解释器:Python 2.7.6 (default, Nov 10 2013, 19:24:18) ...
- Python 类的继承__init__() takes exactly 3 arguments (1 given)
类(class),可以继承基类以便形成具有自己独特属性的类,我们在面向对象的编程中,经常用到类及其继承,可以说没有什么不是类的,今天我们就来详细探讨一下在python中,类的继承是如何做的. 我们假设 ...
- python类、继承
Python 是一种面向对象的编程语言.Python 中的几乎所有东西都是对象,拥有属性和方法.类(Class)类似对象构造函数,或者是用于创建对象的"蓝图". 一.python ...
- python类的继承和多态,获取对象信息
继承 类的继承机制使得子类可以继承父类中定义的方法,拥有父类的财产,比如有一个Animal的类作为父类,它有一个eat方法: class Animal(object): def __init__(se ...
- day30 python类的继承,抽象类等
Python之路,Day17 = Python基础17-面向对象入门 继承 class Student(People): pass print(Student.__bases__) # 查看 Stud ...
- python类的继承、多继承及其常用魔术方法
继承 一个类可以派生出一个子类,这个子类可以使用父类的属性及方法,也可以在父类的基础上添加自己的独特属性或方法.属性和方法的继承的顺序是先从自己开始,找不到再去找父类,父类没有再找父类的父类,其尽头就 ...
- python类的继承
继承一个类 如果已经定义了Person类,需要定义新的Student和Teacher类时,可以直接从Person类继承: class Person(object): def __init__(self ...
随机推荐
- css技巧-案例
点击进入:http://herry.wuhairui.cn/cssSkill/main.html
- Linux学习笔记之Linux 让进程在后台可靠运行的几种方法
0x00 概述 我们经常会碰到这样的问题,用 telnet/ssh 登录了远程的 Linux 服务器,运行了一些耗时较长的任务, 结果却由于网络的不稳定导致任务中途失败.如何让命令提交后不受本地关闭终 ...
- Python查看关键字和帮助信息
1.查看所有的关键字 >>> help('keywords') Here is a list of the Python keywords. Enter any keyword to ...
- P3317 [SDOI2014]重建(Matrix-tree+期望)
P3317 [SDOI2014]重建 详情看这位神犇的blog 剩下的注释在code里吧....... #include<iostream> #include<cstdio> ...
- 静态代码检查findbugs/阿里巴巴开发规范
findbugs,基本上三类严重的bug检测出来都是比较准确的,如下: 阿里巴巴开发规范 前面两类都是比较重要的: 参考: https://blog.csdn.net/qq_27093465/arti ...
- AnswerOpenCV(1001-1007)一周佳作欣赏
外国不过十一,所以利用十一假期,看看他们都在干什么. 一.小白问题 http://answers.opencv.org/question/199987/contour-single-blob-with ...
- 安装搭建Python2.* 和3.* 环境详细步骤
Python是跨平台的,它可以运行在Windows.Mac和各种Linux/Unix系统上. 安装Python 首先进入Python官方网站,将Python下载下来. win7安装python 在官网 ...
- QT笔记之内存管理
转载:https://blog.csdn.net/myjqc/article/details/8569196 (链接错误解决办法) 我们都知道在C++中,new和delete是成对出现的,那么在QT中 ...
- Eclipse查看Servlet源码
Eclipse查看Servlet源码 @(Java) 1.servlet-api 和 javax.servlet-api的区别 在正式查看Servlet源码前,我们首先要分清楚上述两个jar包的区别. ...
- topcoder srm 510 div1
problem1 link 令$f(x)$表示[0,x]中答案的个数.那么题目的答案为$f(b)-f(a-1)$ 对于$f(x)$来说,假设$x$有$d$位数字,即$[0,d-1]$,那么可以进行动态 ...