记录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 ...
随机推荐
- spring中的springSecurity安全框架的环境搭建
首先在web.xml文件中配置监听器和过滤器 <!--监听器 加载安全框架的核心配置文件到spring容器中--> <context-param> <param-name ...
- kivy 小demo
from kivy.lang.builder import Builder from kivy.uix.boxlayout import BoxLayout from kivy.app import ...
- 保存canvas
http://www.crazybunqnq.com/2018/09/01/PythonSeleniumSaveCanvas/ http://www.webhek.com/post/save-canv ...
- ORA-30377 MV_CAPABILITIES_TABLE not found
Cause: You have used the DBMS_MVIEW.EXPLAIN_MVIEW() API before you have defined the MV_CAPABILITIES_ ...
- Activity之Serializable
Student.java package cn.itcast.wh08.multiactivity.domain; import java.io.Serializable; public class ...
- topcoder srm 485 div1
problem1 link 枚举第一个数和第二个数即可确定公差. problem2 link 设高度为$n$,宽度为$m$,且$n \ge m$ 如果$m \ge 5$,那么答案为0.这个可以通过抽屉 ...
- topcoder srm 340 div1
problem1 link $f[i][L][R]$表示计算到第$i$个,最小最大值是$L,R$时的最少个数. import java.util.*; import java.math.*; impo ...
- git用法-打补丁【转】
本文转载自:https://www.cnblogs.com/yandufeng/p/5580765.html 1. git cherry-pick 作用:从一个branch上选择一个commit,添加 ...
- Linux 题目收集
目录 1.库函数,系统调用,用户态及内核态 2.查看进程,杀死进程 3.查看文档 4.scp命令 5.不在 sudoers 文件中.此事将被报告 6.chmod: 更改"minikube&q ...
- Linux/shell: remove adjacent similar patterns
cat > temp004AA1abcAA2AA3abcAA4abcAA5AA6 awk 'BEGIN {pre=0; str="";} { if(NR==1){ i ...