Language/Python

Changes in Python 3.6

LuCeT3 2016. 12. 24.
728x90
반응형

1. f string formatting (PEP 498)


You can avoid the inconvenience of having to kill variables when using the .format () method or%.


>>> lang = 'Python' >>> author = 'Guido van Rossum' >>> 'Language: {}, Author: {}'.format(lang, author) Language: Python, Author: Guido van Rossum >>> f'Language: {lang}, Author: {author}' Language: Python, Author: Guido van Rossum


2. Type hint (PEP 484) In 3.5, type hinting, which was available only to the function's transfer pointer or return value, can be applied to a variable. Since Python is a dynamic language, type hints are not used as a means of error detection, but are used by third parties such as PyCharm to show type hints during autocompletion. (See the PyCharm blog)


>>> value: str >>> value = 'test str' >>> value 'test str' >>> value = 123 >>> value 123


3. Use for numeric values (PEP 515) You can use underscores (_) in numeric values. You can lessen the inconvenience of digits when reading numeric values.


>>> 1000 1000 >>> 1_000 1000


If you see the primitive way of putting it directly, you can use string formatting.


>>> value = 12345678 >>> f'{value:_}' 12_345_678 >>> '{:_}'.format(value)


4. The async generator (PEP 525)

You can use the async / await syntax for the generator.


import asyncio async def gen(x): for i in range(x): yield i await asyncio.sleep(1)



5. async abbreviation (PEP 530) You can also use async / await for grammar such as shorten list, dict abbreviation.


result = [i async for i in aiter() if i % 2] result = [await fun() for fun in funcs if await condition()]



6. Class definition grammar simplification (PEP 487) Defining __init_subclass__ in the parent class simplifies inheritance class definition.


class BlogBase: def __init_subclass__(cls, name, **kwargs): cls.name = name super().__init_subclass__(**kwargs) class Blog(BlogBase, name="raccoony's cave"): pass >>> Blog.name "raccoony's cave"

728x90
반응형

'Language > Python' 카테고리의 다른 글

base 64 원하는 횟수만큼 decoding 하기 python (파일 넣어서)  (0) 2016.12.22
individual bands of image.py  (0) 2016.12.21
RGB image analysis.py  (0) 2016.12.21
image GPS.py  (0) 2016.12.21
base image.py  (0) 2016.12.21

태그

,

댓글0