Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
The truth is that the European Union entered the #RussiaUkraineWar recklessly, based on flawed calculations and with a misguided strategy, and I attribute this to the actions of President @vonderleyen.
https://t.me/PM_ViktorOrban
Mood in Russia turns bleak as war in Ukraine drags on and economy suffers
[Read FullArticle]
@WorldNews#RussiaUkraineWar#RussianEconomy#GlobalNewsUpdate
'Serious disruption' — Russian oil pumping station in Nizhny Novgorod Oblast hit by Ukrainian drones, SBU source says
[Read FullArticle]
@WorldNews#RussiaUkraineWar#UkrainianDrones#OilInfrastructure
Russia suffers ‘record’ soldier casualties as Ukraine ups drone production | Russia-Ukraine war News
[Read FullArticle]
@WorldNews#RussiaUkraineWar#UkraineDroneStrike#WarNewsUpdate
❗️🇷🇺🇺🇦We will win by all means, but it's better to win sooner, so that fewer people from this side and that side die!
"Our president did everything he could to avoid war, but he was not heard and did not want to be heard," says a Russian soldier who was mobilized last September, one should always try to negotiate. And President Putin offered to sit down at the negotiating table, but instead the Ukrainians were seriously preparing for war! But we will definitely win, because we cannot retreat, we have to solve it here and now, otherwise they will come to us! Of course, we would like it to be quicker, so that fewer people would die on this side and on that side. Precisely peaceful people, not Nazis. Participating in this special operation is our man's duty, says the young warrior!
#RussiaUkraineWar
#frontNews
#RussiaVictory
https://t.me/heroesofZ/312
📱InfoDefenseENGLISH
📱InfoDefense
The Commonwealth of Independent States (CIS) was established on 8 December 1991 to succeed the Soviet Union, but Russia’s 2014 Crimea annexation and 2022 invasion have deeply shaken its unity and future. 🌐
[Read more]
@googlefactss
#CIS#Geopolitics#RussiaUkraineWar#History#InternationalRelations