[英]Python: How to type hint for an object of any class?
In typescript you could type hint for an array of any object: 在打字稿中,您可以为任何对象的数组键入提示:
const users: {}[];
Or an array of anything at all: 或任何东西的数组:
const users: any[];
How you would type hint for a list of any class in python? 如何在Python中键入提示以获取任何类的列表?
users: List[Dict] # like this?
Or, if impossible, what about a list of just anything? 或者,如果不可能的话,那么什么清单呢?
users: List[any] # something like this?
The literal equivalent of Typescript's any
is typing.Any
. Typescript的
any
的字面等效项是typing.Any
。 However, you simply don't need to specify further if you don't want to: 但是,如果您不想执行以下操作,则无需进一步指定:
users: List
This means users
is a list, but doesn't specify in detail what that list may contain. 这意味着
users
是一个列表,但没有详细说明该列表可能包含的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.