【问题标题】:What exactly self and -> int mean in this python snippet def line1(self, arr: List[int], a: int, b: int, c: int) -> int: [duplicate]在这个 python 片段中 self 和 -> int 到底是什么意思 def line1(self, arr: List[int], a: int, b: int, c: int) -> int: [duplicate]
【发布时间】:2020-08-03 01:31:08
【问题描述】:

对于下面的蟒蛇sn-p,

def line1(self, arr: List[int], a: int, b: int, c: int) -> int:

-> int 是什么意思?那么 b:int 的目的是什么?还有self是什么意思?

【问题讨论】:

标签: python-3.x


【解决方案1】:

请至少尝试使用 Google。这些都是非常简单的问题。

但无论如何:

self - 表示一个函数属于一个类,使用 self 将所有类属性传递给函数,以便它可以访问它们

-> - 是python中一个相对较新的特性,它有助于类型注释,它定义了函数将返回什么。在这种情况下,函数应该返回一个整数值。

: - 与上面的“箭头”具有相同的用途,这意味着函数期望接收 a、b 和 c 的整数值

您在 cmets 中找到了一些有用的链接,请查看它们。

【讨论】:

    猜你喜欢
    • 2019-10-31
    • 1970-01-01
    • 2011-01-11
    • 2014-10-19
    • 2018-06-16
    • 2016-05-24
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多