Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🔺“Yemen does not kneel. It responds.”
Yemen shows steadfast solidarity with Palestine, proving through sacrifice and resistance what true commitment to justice means.
Watch in full
#BlackAndWhite
@PresstvPrograms
🔺Nicola Hadwa argues that Israel faces collapse in population, economy, and legitimacy, while Palestinian resistance grows stronger.
Watch in full
#BlackAndWhite
@PresstvPrograms
🔺“Israeli regime cannot exist in peace”
Nicola Hadwa states that the Palestinian resistance fights bravely against the Israeli regime over the past two years, emphasizing the regime’s failure to achieve its goals.
Watch in full
#BlackAndWhite
@PresstvPrograms
🔺“Yemenis are fierce fighters who do not know the meaning of defeat”
According to Nicola Hadwa, Saudi Arabia and the UAE are complicit in the Israeli regime's crimes against the Yemeni people.
Watch in full
#BlackAndWhite
@PresstvPrograms
🔺”Yemen showed that Israel’s army is not invincible”
Nicola Hadwa points out that Yemen has shown that the child-killing entity, Israel, is not an invincible army and is, in fact, a considerably a weaker army.
Watch in full
#BlackAndWhite
@PresstvPrograms
🔺 Nicola Hadwa explains why Yemen’s role in supporting the Palestinians is truly impressive and remarkable.
Watch in full
#BlackAndWhite
@PresstvPrograms
🔺"Out of every 10 words from the West, 15 are lies."
Nicola Hadwa exposes Western media’s demonization of Yemen, highlighting the nation’s resilience as a symbol of anti-imperial resistance.
Watch in full
#BlackAndWhite
@PresstvPrograms
🔺Yemen, though poor and besieged, embodies defiant solidarity, transforming its suffering into a force for resistance against oppression.
Watch in full
#BlackAndWhite
@PresstvPrograms
🔺 Yemen does not give up
From Yemen, in a show of solidarity with the Palestinian cause, ships associated with the Zionist entity and imperialism are being targeted, disrupting the transfer of goods and products that would support the Israeli regime and its trade.
Watch in full
#BlackAndWhite
@PresstvPrograms
🔺"Cuba will not give up"
Carmen Esquivel emphasizes that Cuba remains steadfast in defending its sovereignty against external challenges.
Watch in full
#BlackAndWhite
@PresstvPrograms
🔺According to Carmen Esquivel, Cuba must strengthen ideology, media, and social unity to protect its socialist revolution.
Watch in full
#BlackAndWhite
@PresstvPrograms