Python3 基础教程 - 廖雪峰.................................................................................. 64 使用 dict 和 set .................................................................................................. 参考源码 do_for.py Python3 基础教程【完整版】 http://www.yeayee.com/ 67/531 do_while.py 使用 dict 和 set dict Python 内置了字典:dict 的支持,dict 全称 dictionary,在其他语言中也 称为 map,使用键-值(key-value)存储,具有极快的查找速度。 TypeError: unhashable type: 'list' set set 和 dict 类似,也是一组 key 的集合,但不存储 value。由于 key 不能 重复,所以,在 set 中,没有重复的 key。 要创建一个 set,需要提供一个 list 作为输入集合: >>> s = set([1, 2, 3]) >>> s {1, 2, 3} Python30 码力 | 531 页 | 5.15 MB | 1 年前3
Tornado 6.1 Documentation
tornado.tcpserver — Basic IOStream-based TCP server Coroutines and concurrency tornado.gen — Generator-based coroutines tornado.locks – Synchronization primitives tornado.queues – Queues for coroutines my_future = Future() fetch_future = http_client.fetch(url) def on_fetch(f): my_future.set_result(f.result().body) fetch_future.add_done_callback(on_fetch) return my_future Notice that yield is a generator. All generators are asynchronous; when called they return a generator object instead of running to completion. The @gen.coroutine decorator communicates with the generator via the yield0 码力 | 931 页 | 708.03 KB | 1 年前3
Tornado 6.0 Documentation
compatible with Tornado. Applications that use Tornado on Windows with Python 3.8 must call asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) at the beginning of their main file/function tornado.tcpserver — Basic IOStream-based TCP server Coroutines and concurrency tornado.gen — Generator-based coroutines tornado.locks – Synchronization primitives tornado.queues – Queues for coroutines my_future = Future() fetch_future = http_client.fetch(url) def on_fetch(f): my_future.set_result(f.result().body) fetch_future.add_done_callback(on_fetch) return my_future Notice that0 码力 | 869 页 | 692.83 KB | 1 年前3
Python 标准库参考指南 3.6.15 8 二进制序列类型—bytes, bytearray, memoryview . . . . . . . . . . . . . . . . . . . . . . . 50 4.9 集合类型—set, frozenset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 4.10 映射类型—dict globals() map() reversed() __import__() complex() hasattr() max() round() delattr() hash() memoryview() set() abs(x) 返回一个数的绝对值。实参可以是整数或浮点数。如果实参是一个复数,返回它的模。 all(iterable) 如果 iterable 的所有元素为真(或迭代器为空),返回 True class dict(iterable, **kwarg) 创建一个新的字典。dict 对象是一个字典类。参见dict 和映射类型—dict 了解这个类。 其他容器类型,请参见内置的list、set 和tuple 类,以及collections 模块。 dir([object]) 如果没有实参,则返回当前本地作用域中的名称列表。如果有实参,它会尝试返回该对象的有效属性 列表。 如果对象有一个名为0 码力 | 1886 页 | 8.95 MB | 9 月前3
Python 标准库参考指南 3.6.15 8 二进制序列类型—bytes, bytearray, memoryview . . . . . . . . . . . . . . . . . . . . . . . 50 4.9 集合类型—set, frozenset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 4.10 映射类型—dict globals() map() reversed() __import__() complex() hasattr() max() round() delattr() hash() memoryview() set() abs(x) 返回一个数的绝对值。实参可以是整数或浮点数。如果实参是一个复数,返回它的模。 all(iterable) 如果 iterable 的所有元素为真(或迭代器为空),返回 True class dict(iterable, **kwarg) 创建一个新的字典。dict 对象是一个字典类。参见dict 和映射类型—dict 了解这个类。 其他容器类型,请参见内置的list、set 和tuple 类,以及collections 模块。 dir([object]) 如果没有实参,则返回当前本地作用域中的名称列表。如果有实参,它会尝试返回该对象的有效属性 列表。 如果对象有一个名为0 码力 | 1886 页 | 8.95 MB | 9 月前3
Python 标准库参考指南 2.7.18 Sequence Types —str, unicode, list, tuple, bytearray, buffer, xrange . . . . . . . . 35 5.7 集合类型—set, frozenset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 5.8 映射类型—dict . . . . . . . . . . . . . . . . . . . . . . . . 1122 25 开发工具 1123 25.1 pydoc —Documentation generator and online help system . . . . . . . . . . . . . . . . . . . . . . . 1123 25.2 doctest —测试交互性的 max() reversed() zip() compile() hasattr() memoryview() round() __import__() complex() hash() min() set() delattr() help() next() setattr() dict() hex() object() slice() dir() id() oct() sorted() In0 码力 | 1552 页 | 7.42 MB | 9 月前3
Python 标准库参考指南 2.7.18 Sequence Types —str, unicode, list, tuple, bytearray, buffer, xrange . . . . . . . . 35 5.7 集合类型—set, frozenset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 5.8 映射类型—dict . . . . . . . . . . . . . . . . . . . . . . . . 1122 25 开发工具 1123 25.1 pydoc —Documentation generator and online help system . . . . . . . . . . . . . . . . . . . . . . . 1123 25.2 doctest —测试交互性的 max() reversed() zip() compile() hasattr() memoryview() round() __import__() complex() hash() min() set() delattr() help() next() setattr() dict() hex() object() slice() dir() id() oct() sorted() In0 码力 | 1552 页 | 7.42 MB | 9 月前3
Python 标准库参考指南 2.7.18 Sequence Types —str, unicode, list, tuple, bytearray, buffer, xrange . . . . . . . . 35 5.7 集合类型—set, frozenset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 5.8 映射类型—dict . . . . . . . . . . . . . . . . . . . . . . . . 1122 25 开发工具 1123 25.1 pydoc —Documentation generator and online help system . . . . . . . . . . . . . . . . . . . . . . . 1123 25.2 doctest —测试交互性的 max() reversed() zip() compile() hasattr() memoryview() round() __import__() complex() hash() min() set() delattr() help() next() setattr() dict() hex() object() slice() dir() id() oct() sorted() In0 码力 | 1552 页 | 7.42 MB | 9 月前3
Jinja2 Documentation Release 2.10is specified this defaults to ‘ASCII’ which means that you can’t use any non ASCII identifier. To set a better module encoding add the following comment to the first or second line of the Python module returning str for strings that fit into ASCII and for everything else unicode: >>> m = Template(u"{% set a, b = 'foo', 'föö' %}").module >>> m.a 'foo' >>> m.b u'f\xf6\xf6' 2.3 High Level API The high-level version 2.2. trim_blocks If this is set to True the first newline after a block is re- moved (block, not variable tag!). Defaults to False. lstrip_blocks If this is set to True leading spaces and tabs are0 码力 | 148 页 | 475.08 KB | 1 年前3
Mypy 1.10.0+dev Documentationfunction must accept specifically a list – it would run just fine if you were to pass in a tuple, a set, or any other custom iterable. You can express this idea using collections.abc.Iterable [https://docs collections on Python 3.9+, the type of the collection item is in brackets x: list[int] = [1] x: set[int] = {6, 7} # For mappings, we need the types of both keys and values x: dict[str, float] = {"field": capitalized, and the type is imported from the 'typing' module from typing import List, Set, Dict, Tuple x: List[int] = [1] x: Set[int] = {6, 7} x: Dict[str, float] = {"field": 2.0} x: Tuple[int, str, float] =0 码力 | 318 页 | 270.84 KB | 1 年前3
共 520 条
- 1
- 2
- 3
- 4
- 5
- 6
- 52













