python - 为什么这个参数在这个 super().__init__() 方法中出现了两次?
问题描述
为什么在 Square 类中super().__init__(length, length)
有两个长度参数。
这段代码来自我正在阅读的一篇文章,试图理解 Python 中的 super() 函数。我非常感谢一些建议。提前致谢。
class Rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
return self.length * self.width
def perimeter(self):
return 2 * self.length + 2 * self.width
# Here we declare that the Square class inherits from the Rectangle class
class Square(Rectangle):
def __init__(self, length):
# This is the line that I don't understand.
super().__init__(length, length)
解决方案
推荐阅读
- oauth - Aouth 2.0 谁来管理 2 认证类型?
- angular - 角度获取子属性不仅是id
- python - 如何使用 Python 沿 x 轴分箱 2D 数据
- selenium - Selenium:捕获 NoSuchElementException 出现在可点击元素上是否有用?
- java - Jackson: understand if source JSON is an array or an object
- c - C language: memory allocation of a structure of two char* pointers
- mongodb - 通过 Spring Data mongoDb 或 mongo 模板仅从 MongoDB 获取嵌套对象
- google-apps-script - 无法从 Google Apps 脚本调用亚马逊 MWS API 'GetLowestPricedOffersForSKU' Post 调用。
- c# - 无法使用 LinQ c# 从 DB 中选择特定字段
- backbone.js - backbone.js: Right-hand side of 'instanceof' is not an object