Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python代码中的name:Set[str]=Set()是什么?_Python_Python 3.x - Fatal编程技术网

Python代码中的name:Set[str]=Set()是什么?

Python代码中的name:Set[str]=Set()是什么?,python,python-3.x,Python,Python 3.x,我有如下代码: def _check(self) -> None: cars = self.cars.all() cars.sort(key=self.key) names: Set[str] = set() 有人能给我解释一下代码名:Set[str]=Set()在做什么吗?这是一个带有。它声明变量names的类型是带有字符串值的集合类型,初始化为空集合(=set())。这是带有字符串值的初始化。它声明变量names的类型是一个带有字符串值的集合类型,它被初始化为

我有如下代码:

def _check(self) -> None:
    cars = self.cars.all()
    cars.sort(key=self.key)
    names: Set[str] = set()

有人能给我解释一下代码名:Set[str]=Set()在做什么吗?

这是一个带有。它声明变量
names
的类型是带有字符串值的集合类型,初始化为空集合(
=set()
)。

这是带有字符串值的初始化。它声明变量
names
的类型是一个带有字符串值的集合类型,它被初始化为一个空集(
=set()
)。

它创建一个空集,键入
names
作为一组字符串的引用。它创建一个空集,键入
names
作为一组字符串的引用。