【python】| python3.6新特性整理

1. 字典key值排序

In [1]: def pep468(**kwargs):
   ...:     print(list(kwargs.keys()))
   ...:     

In [2]: pep468(a=1, b=2, c=3)
['a', 'b', 'c']

2. 创建/定制类更简单

- PEP 487: Simpler customization of class creation

In [1]: class PEP487(object):
   ...:     def __init_subclass__(cls, whom, **kwargs):
   ...:         super().__init_subclass__(**kwargs)
   ...:         cls.hello = lambda: print(f"hello, {whom}")
   ...:         

In [2]: class HelloWorld(PEP487, whom="World"):
   ...:     pass
   ...: 

In [3]: HelloWorld.hello()
hello, World
展开阅读全文

没有更多推荐了,返回首页