tuple[str, ...]和tuple[str]的区别是什么?(python打字)
发布于 2022-04-25 14:26:14
给出带有省略号的元组类型意味着不知道这个元组中的元素数,但是类型是已知的:
x: tuple[str, ...] = ("hi",) #VALID
x: tuple[str, ...] = ("hi", "world") #ALSO VALID不使用省略号意味着元组具有特定数量的元素,例如:
y: tuple[str] = ("hi", "world") # Type Warning: Expected type 'Tuple[str]', got 'Tuple[str, str]' instead 这与其他集合的表示法不同,例如,list[str]是指具有str类型元素的任意长度的列表。
https://stackoverflow.com/questions/72001132
复制相似问题