Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в Python в модуле re.
Чтобы указать флаг для компилятора нам надо указать его после передаваемой строки. Например, добавляем флаг для игнорирования переноса строки.
pattern = re.compile(r"(\w+)+")
words = pattern.search(text, re.DOTALL)
А как указать несколько флагов? Ведь явно будут ситуации когда нам потребуется больше одного. Кто читал посты по битовые операторы уже понял как.
pattern.search(text, re.DOTALL | re.VERBOSE)
А теперь смотрим исходники, что находится в этих атрибутах?
Не удивительно, степени двойки. Почему? Потому что каждое следующее значение это сдвиг единицы влево.
>>> for n in [1, 2, 4, 8, 16, 32, 64, 128, 256]:
>>>
print(bin(n))
0b1
0b10
0b100
0b1000
0b10000
0b100000
0b1000000
0b10000000
0b100000000
Чтобы было понятней, давайте напишем тоже самое но иначе, добавим ведущие нули:
000000001
000000010
000000100
000001000
000010000
000100000
001000000
010000000
100000000
Не понятно что тут происходит? Читай три поста про битовые операторы начиная с этого ➡️https://t.me/pythonotes/45
В общем, это пример применения побитовых операций в самом Python.
Теперь вы знаете Python еще немного лучше)
#tricks#regex#libs
🔥 OGCommunity App for daily activity and grabbing OGC tokens for free and many more.
👉 Join Bot for Airdrop :- https://t.me/OGCommunityBot?start=i09w6Cfm9nz7V5wMcLjJVJpz
➖ Click on bot link
➖ Click on open app
➖ Complete tasks to get instant OGC tokens
➖ Mine every day & Done
#Note :- Join fast before #May 31st 🔥
Wikipedia每日一图(#May 16, 2026)https://ift.tt/ixodInV
Partially frozen Gurudongmar Lake, a glacial lake located to the north of the Himalayas in the northeast Indian state of Sikkim at an altitude of over 5,150 metres (16,900 ft). The lake is fed by glaciers of the Khangchengyao massif, forms the headwaters of the Teesta river and is considered sacred by Buddhists and Sikhs. Today is Sikkim Day, which commemorates the formation of Sikkim as a state of India in 1975, following a popular referendum and full merger after decades of being a protectorate since 1947.. 了解更多 . #Wikipedia每日一图
Wikipedia每日一图(#May 14, 2026)https://ift.tt/TXQ67sq
This stained glass window in the Cathedral of Saint Julian of Le Mans (Le Mans, France) depicts the Virgin Mary and the apostles during the Ascension of Jesus. Today is the Feast of the Ascension in Western Christianity.. 了解更多 . #Wikipedia每日一图
Wikipedia每日一图(#May 13, 2026)https://ift.tt/UjxK9Pg
This azulejo from the Igreja de São Bento (Ribeira Brava, Madeira, Portugal) depicts Our Lady of Fátima. Today is the feast of Our Lady of Fátima in the Catholic Church and the 110th anniversary of her first apparition to three shepherd children.. 了解更多 . #Wikipedia每日一图
Wikipedia每日一图(#May 12, 2026)https://ift.tt/EpzY47y
Aerial view of the ruins of Takht-i-Bahi, a 1st-century CE Buddhist monastery complex located in what was once the ancient Indian region of Gandhara, in the present-day northern Pakistani province of Khyber Pakhtunkhwa. It is representative of Buddhist monastic architecture from its era and the ruins were listed as a World Heritage Site in 1980, with UNESCO describing it as having been "exceptionally well-preserved".. 了解更多 . #Wikipedia每日一图
Wikipedia每日一图(#May 10, 2026)https://ift.tt/82UdYl5
Flower buds in development of a Crocosmia 'Lucifer' (Montbretia). Focus stack of 54 photos.. 了解更多 . #Wikipedia每日一图