使用Python 3的功能注释,可以指定包含在同类列表(或其他集合)中的项的类型,以便在PyCharm和其他IDE中进行类型提示。
一个int列表的伪python代码示例:
def my_func(l:list<int>):
pass
我知道有可能使用Docstring ...
def my_func(l):
"""
:type l: list[int]
"""
pass
...但是我更喜欢注释样式。
type object is not subscriptable
在定义函数时。显然,您可以使用字符串:def my_func(L: 'list[int]')
但是我不知道PyCharm是否会在解析文档字符串时对其进行解析……
'list[int]'
,如果不清楚的话,我们深表歉意。