3
A
回答
1
让我们来看看:
typing.List<~T>[typing.Tuple[int]]
typing.List
意味着List
<~T>
从typing
库类型,名为意味着这种类型是通用的,它是在另一种类型的T定义的[typing.Tuple[int]]
意味着类型T是类型Tuple[int]
。
在自然语言,你可以这样写的定义:
typing.List<~T>[typing.Tuple[int]]
:一为int的标准列表元组
3
这不是实际的Python语法,所以不要尝试在程序中使用它。也就是说,这是他们如何选择表示泛型类型的类型参数。在泛型类型的repr
中,声明的类型参数在类似Java的<>
尖括号中列出,并且在每个类型参数之前使用+
,-
或~
,具体取决于该参数是协变,逆变还是不是。
typing.List
接受名为T
单个非协变,非逆变类型参数,所以它的名字后,得到了<~T>
。
您会注意到typing.Tuple
的名字后没有任何<>
的东西。 Tuple
是一个奇怪的特例,因为它需要可变数量的类型参数。
+0
''<~T>'/'<+T>'/'<-T>'从3.6开始,python消失了。它现在只是打印'typing.List [typing.Tuple [int]]',所以你看不到它的方差。我找不到与此相关的问题,否则我会要求将它恢复原状:) – max
相关问题
- 1. 从字典<int,List <Tuple <string,object >>>到Dictionary <int,List <Tuple <string,object,AnEnum >>> with LINQ
- 2. List <JAXBElement <?是什么?扩展SomeClassName >>的意思是?
- 3. Simply IEnumerable <int> to List <KeyValuePair <int, int>>?
- 4. list <myClass<int> *> sort
- 5. 为什么是List <>。OrderBy LINQ比IComparable + List <>更快。
- 6. List <int> to IEnumerable <IComparable>
- 7. Puppet中'if $ variable {}'的意思是什么?</p> <pre><code>if $variable { do something } </code></pre> <p>这是什么意思:
- 8. IDictionary <String,List <OpenXmlCompositeElement >> - 获取List <OpenXmlCompositeElement>?
- 9. List <Map <String,List <>>> in BaseAdapter,Android
- 10. List <Map <String,String >> vs List <Object>
- 11. 什么是什么是一个使用</p> <p><code>javac -cp classes helloworld.java</code></p> <p>和</p> <p><code>javac -classpath classes helloworld.java</code></p> 在CMD <p>的区别-cp和-classpath
- 12. 这是什么意思(计算中的<< and > >>)?
- 13. 什么` “</p> <pre><code>__m_uvm_status_container.scope.set_arg_element(`"ARG`",i); </code></pre> <p>什么的<code>"ARG</code>在宏SV
- 14. 如何unordered_set <tuple <int,int>>?
- 15. 人<Person>,什么是<Person>?
- 16. 为什么“testScores [”dave“]”的类型是“可选<Array<Int>> .Type”而不是“<Array<Int>> .Type”
- 17. 什么是<script type =“text/javascript”><!--mce:0--></script>?
- 18. 为什么<textarea>显示<>而不是< >?
- 19. 使用>>,>,> |,||,| <,<,<<,<<
- 20. matplotlib中的axes.flat是做什么的?</p> <pre><code>for i, ax in enumerate(axes.flat): </code></pre> <p>这是什么做的:
- 21. 浮动元素<br /><br /><br /><br /><br /\><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
- 22. convert <vector><string> TO <vector><int> C++,Win32
- 23. 如何将List <IEnumerable <ProductViewModel >>转换为<IEnumerable <ProductViewModel >>?
- 24. 为什么我们写ArrayList <ArrayList <Integer>> list = new ArrayList <>();
- 25. if(<object> == <int>)
- 26. Post Map <String,List <String>>
- 27. Sort Map <String,List <Object[]>>
- 28. IList <InterfaceType>为List <ImplementsInterfaceType>?
- 29. groovy中的地图语法?</p> <pre><code>a[x,y] </code></pre> <p>是什么意思:
- 30. 的MySQL/PHP:<code>id</code>,<code>name</code>,<code>category</code>和一个<code>ratings</code>表列:<code>id</code>,<code>item</code>,<code>rating</code>如何使用JOIN语句
你是什么意思*“它来自哪里”*? – jonrsharpe
'List <~T>'只是基于[源代码](https://hg.python.org/cpython/file/3.5/Lib/typing.py#l489)的泛型类型'T'的列表' 〜'表示既不共同也不反对。 – jonrsharpe