File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 3131### python_aiohttp.py: Python中最好用的异步爬虫库Aiohttp代码实例
3232
3333### python_thread_multiprocess.py: Python进阶: 聊聊IO密集型任务、计算密集型任务,以及多线程、多进程
34+
35+ ### python_version36.py: Python3.6正式版要来了, 你期待哪些新特性?
3436===================================================================================================
3537
3638### 您可以fork该项目,并在修改后提交Pull request
Original file line number Diff line number Diff line change 1+ # _*_ coding: utf-8 _*_
2+
3+ """
4+ python_version36.py by xianhu
5+ """
6+
7+ import asyncio
8+ import decimal
9+ from typing import List , Dict
10+
11+ # Formatted string literals
12+ name = "Fred"
13+ print (f"He said his name is { name } ." ) # 'He said his name is Fred.'
14+ print ("He said his name is {name}." .format (** locals ()))
15+
16+ width = 10
17+ precision = 4
18+ value = decimal .Decimal ("12.34567" )
19+ print (f"result: { value :{width }.{precision }} " ) #'result: 12.35'
20+
21+
22+ # variable annotations
23+ def test (a : List [int ], b : int ) -> int :
24+ return a [0 ] + b
25+ print (test ([3 , 1 ], 2 ))
26+
27+ primes : List [int ] = []
28+ captain : str
29+
30+ class Starship :
31+ stats : Dict [str , int ] = {}
32+
33+
34+ # Underscores in Numeric Literals
35+ a = 1_000_000_000_000_000 # 1000000000000000
36+ b = 0x_FF_FF_FF_FF # 4294967295
37+
38+ '{:_}' .format (1000000 ) # '1_000_000'
39+ '{:_x}' .format (0xFFFFFFFF ) # 'ffff_ffff'
40+
41+
42+ # Asynchronous Generators
43+ async def ticker (delay , to ):
44+ """Yield numbers from 0 to *to* every *delay* seconds."""
45+ for i in range (to ):
46+ yield i
47+ await asyncio .sleep (delay )
48+
49+
50+ # Asynchronous Comprehensions
51+ result = [i async for i in aiter () if i % 2 ]
52+ result = [await fun () for fun in funcs if await condition ()]
You can’t perform that action at this time.
0 commit comments