BOOKPYTHON Telegram 3412
Если вы хотите игнорировать какое-то исключение, вы, вероятно, сделаете что-то вроде этого:


try:
lst = [1, 2, 3, 4, 5]
print(lst[10])
except IndexError:
pass


Это будет работать (ничего не выводя), но contextlib позволяет сделать то же самое более выразительно и семантически правильно:


from contextlib import suppress
with suppress(IndexError):
lst = [1, 2, 3, 4, 5]
lst[10]

👉@BookPython
👍5



tgoop.com/BookPython/3412
Create:
Last Update:

Если вы хотите игнорировать какое-то исключение, вы, вероятно, сделаете что-то вроде этого:


try:
lst = [1, 2, 3, 4, 5]
print(lst[10])
except IndexError:
pass


Это будет работать (ничего не выводя), но contextlib позволяет сделать то же самое более выразительно и семантически правильно:


from contextlib import suppress
with suppress(IndexError):
lst = [1, 2, 3, 4, 5]
lst[10]

👉@BookPython

BY Библиотека Python разработчика | Книги по питону


Share with your friend now:
tgoop.com/BookPython/3412

View MORE
Open in Telegram


Telegram News

Date: |

The administrator of a telegram group, "Suck Channel," was sentenced to six years and six months in prison for seven counts of incitement yesterday. 5Telegram Channel avatar size/dimensions Ng, who had pleaded not guilty to all charges, had been detained for more than 20 months. His channel was said to have contained around 120 messages and photos that incited others to vandalise pro-government shops and commit criminal damage targeting police stations. The group’s featured image is of a Pepe frog yelling, often referred to as the “REEEEEEE” meme. Pepe the Frog was created back in 2005 by Matt Furie and has since become an internet symbol for meme culture and “degen” culture. How to Create a Private or Public Channel on Telegram?
from us


Telegram Библиотека Python разработчика | Книги по питону
FROM American