擅长:python、mysql、java
<p>此语法现在在<a href="https://docs.python.org/3/whatsnew/3.9.html#type-hinting-generics-in-standard-collections" rel="nofollow noreferrer">Python 3.9+</a>中有效:</p>
<blockquote>
<p>In type annotations you can now use built-in collection types such as <code>list</code> and <code>dict</code> as generic types instead of importing the corresponding capitalized types (e.g. <code>List</code> or <code>Dict</code>) from <code>typing</code>.</p>
</blockquote>
<p>但是,在3.9之前,您需要使用导入的<code>List</code>或<a href="https://www.python.org/dev/peps/pep-0563/#enabling-the-future-behavior-in-python-3-7" rel="nofollow noreferrer">in Python 3.7+</a>来添加</p>
<pre class="lang-py prettyprint-override"><code>from __future__ import annotations
</code></pre>
<p>在文件顶部,允许使用<code>list[int]</code>(例如)</p>