๐’ƒ๐’†๐’‚๐’–๐’•๐’š ๐’Š๐’๐’•๐’†๐’๐’๐’Š๐’ˆ๐’†๐’๐’•
Published 2016. 12. 24. 01:24
Changes in Python 3.6 Language
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
๋ฐ˜์‘ํ˜•
profile

๐’ƒ๐’†๐’‚๐’–๐’•๐’š ๐’Š๐’๐’•๐’†๐’๐’๐’Š๐’ˆ๐’†๐’๐’•

@๐“›๐“พ๐“ฌ๐“ฎ๐“ฝ๐“ฎ_๐“ข๐“ฝ๐“ฎ๐“ต๐“ต๐“ช

ํฌ์ŠคํŒ…์ด ์ข‹์•˜๋‹ค๋ฉด "์ข‹์•„์š”โค๏ธ" ๋˜๋Š” "๊ตฌ๋…๐Ÿ‘๐Ÿป" ํ•ด์ฃผ์„ธ์š”!

profile on loading

Loading...