TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #418 · 9 мар.

Оператор pipe позволяет писать более компактный код, реализуя логику объединения данных (Union). Важно помнить, что его поведение зависит от контекста. Побитовые операции (логическое OR) result = 5 | 3 # 5 (0101) | 3 (0011) = 7 (0111) Самое главное - не путать с оператором or, это другое! Объединение множеств set_a = {1, 2, 3} set_b = {3, 4, 5} set_c = set_a | set_b # {1, 2, 3, 4, 5} set_c |= {5, 6} # {1, 2, 3, 4, 5, 6} Слияние словарей dict_1 = {"a": 1, "b": 2} dict_2 = {"b": 3, "c": 4} merged = dict_1 | dict_2 # {'a': 1, 'b': 3, 'c': 4} merged |= {"d": 5} # {'a': 1, 'b': 3, 'c': 4, 'd': 5} Аннотации типов, заменяет Union def process_data(value: int | str) -> None: print(value) Допустимо использовать в isinstance или issubclass isinstance(3, int | float) # True Паттерн-матчинг status_code = 404 match status_code: case 200 | 201 | 204: print("OK") case 400 | 404 | 500: print("ERROR") Для использования в своих классах требуется переопределить метод __or__ Так же нашел библиотеку pipe которая добавляет еще много возможностей. Рекомендую ознакомиться ;) #basic

Hashtags

Резултати

Пронајдени 159 слични објави

Пребарај: #breakingnews

当前筛选 #breakingnews清除筛选
HAMAS-ISRAEL WAR

@HAMASW · Post #8739 · 09.05.2024 г., 06:38

#BREAKINGNEWS 🔴 US President Biden confessed - Were these bombs that were stopped from being shipped to Israel used to kill civilians in Gaza? + They were previously used to kill civilians in Gaza and destroy population centers.

HAMAS-ISRAEL WAR

@HAMASW · Post #8668 · 06.05.2024 г., 11:05

🚨 🚨 🚨#BREAKINGNEWS The occupying Israeli army has launched a very violent attack on the east of Rafah as of now. The attacked areas are the area that Israel demanded to be evacuated in the morning.

HAMAS-ISRAEL WAR

@HAMASW · Post #8640 · 01.05.2024 г., 19:47

🚨#BREAKINGNEWS The Kassam Brigades broadcast the moments of shelling the Israeli occupation forces with heavy caliber mortars in Netsarim, south of Gaza City.

HAMAS-ISRAEL WAR

@HAMASW · Post #8624 · 30.04.2024 г., 10:21

🚨#BREAKINGNEWS A Turkish youth staged a stabbing operation in Israeli-occupied Jerusalem, wounding an Israeli policeman. The youth was martyred. (Haaretz)

123•••10•••1314
ПретходнаСтраница 1 од 14Следна