# _*_ coding: utf-8 _*_"""python_version36.py by xianhu"""import asyncioimport decimalfrom typing import List, Dict# Formatted string literalsname = "Fred"print(f"He said his name is {name}.") # 'He said his name is Fred.'print("He said his name is {name}.".format(**locals()))width = 10precision = 4value = decimal.Decimal("12.34567")print(f"result: {value:{width}.{precision}}") #'result: 12.35'# variable annotationsdef test(a: List[int], b: int) -> int:return a[0] + bprint(test([3, 1], 2))primes: List[int] = []captain: strclass Starship(object):stats: Dict[str, int] = {}# Underscores in Numeric Literalsa = 1_000_000_000_000_000 # 1000000000000000b = 0x_FF_FF_FF_FF # 4294967295'{:_}'.format(1000000) # '1_000_000''{:_x}'.format(0xFFFFFFFF) # 'ffff_ffff'# Asynchronous Generatorsasync def ticker(delay, to):"""Yield numbers from 0 to *to* every *delay* seconds."""for i in range(to):yield iawait asyncio.sleep(delay)# Asynchronous Comprehensionsresult = [i async for i in aiter() if i % 2]result = [await fun() for fun in funcs if await condition()]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。