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"
'Language' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
R script๋ฅผ ์ด์ฉํ ์๊ฐํ (2) | 2022.12.18 |
---|---|
Notepad ๋์ฐ๊ธฐ - Process (0) | 2022.11.07 |
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 |
๋๊ธ