简体   繁体   English

什么是 Python 中列表、元组或集合的合适类型(来自键入模块)

[英]What is a suitable type (from the typing module) for list, tuple or set in Python

Some that I've encountered:我遇到的一些:

  1. typing.ItemsView打字.ItemsView
  2. typing.AbstractSet打字.AbstractSet
  3. typing.Collection打字。集合
  4. typing.Container打字.Container

Which one do you think is most suitable?你觉得哪一款最合适?

as mentioned in the comments typing.union is a nice option, also as mentioned in the comments try and see what one "implements" what your function uses.正如评论中提到的那样, typing.union是一个不错的选择,也如评论中提到的那样,尝试看看你的函数使用的是什么“实现”。

I thinktyping.Collection is the one that covers all of them, but you might be doing something that only needs typing.Iterable .我认为Typing.Collection是涵盖所有这些的一个,但您可能正在做一些只需要Typing.Iterable 的事情

without knowing more about what you are doing it is hard to say.如果不了解更多关于你在做什么,就很难说。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM