如何键入提示返回 map() 对象的函数?

时间:2021-03-18 19:13:11

标签: python python-3.x type-hinting

我的代码中有以下函数(也在所示的类中):

class Range:
    def __init__(self, string_representation: str):
        self.string_representation = string_representation

    # ...

    def get_start_and_end_numbers(self):    # <--- This one
        return map(int, self.string_representation.split('-'))

    # ...

如您所见,它的作用是:给定一个 string_representation'1-4',该函数返回一个 map() 对象,该对象产生整数值 1 和 {{ 1}}。

所以我猜这应该足够了:

4

但是我不会输入提示地图的“内容”,即:整数。

那么,我应该如何输入返回 def get_start_and_end_numbers(self) -> map: return map(int, self.string_representation.split('-')) 对象的提示?

0 个答案:

没有答案