简体   繁体   English

Python 3中词典生成器的文档在哪里?

[英]Where is the documentation for dictionary generators in Python 3?

I mean this: 我的意思是:

>>> d = {a : a ** 2 for a in range(7)}
>>> d
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36}

I managed to find these resources: 我设法找到了这些资源:

These seem to be just tutorials; 这些似乎只是教程。 I want to find it in the documentation itself. 我想在文档本身中找到它。

You are looking for the "Displays for lists, sets and dictionaries" section of the expressions chapter of the reference documentation. 您正在寻找参考文档中“表达式”一章的“显示列表,集合和词典”部分

That section deals with both defining literal lists, sets and dictionaries, as well as comprehension expressions for those types. 该部分涉及定义文字列表,集合和字典,以及这些类型的理解表达式。

For constructing a list, a set or a dictionary Python provides special syntax called “displays”, each of them in two flavors: 为了构造列表,集合或字典,Python提供了称为“显示”的特殊语法,每种语法有两种形式:

  • either the container contents are listed explicitly, or 容器内容明确列出,或
  • they are computed via a set of looping and filtering instructions, called a comprehension. 它们是通过一组称为理解的循环和过滤指令来计算的。

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

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