python打字:元组[str] vs tuple [str,...]
元组[str,...]
vs 元组[str]
有什么区别? (Python打字)
What's the difference between tuple[str, ...]
vs tuple[str]
? (python typing)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用省略者给出元组类型意味着该元组中的元素数量尚不清楚,但是类型是已知的:
不使用省略号意味着具有特定元素数量的元组,例如:
这与其他集合的表示法相反,例如
list [str] 表示任何长度的列表,其中包含
str
的元素。giving a tuple type with ellipsis means that number of elements in this tuple is not known, but type is known:
not using ellipsis means a tuple with specific number of elements, e.g.:
This goes in contrast to notation of other collections, e.g.
list[str]
means list of any length with elements of typestr
.