Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🌎 Trapped in an Andes avalanche in 1972, survivors of a plane crash endured 72 days in freezing mountains, rationing food and melting snow for water—proving human resilience in the harshest conditions. ✨
#survival⚡#history⚡#resilience
👉subscribe Interesting Planet
🌎 The Resurrection Fern can survive months or years without rain by curling up and looking dead. With just a splash of water, it springs back to vibrant green life, showcasing an extraordinary natural survival trick for drought-prone environments. ✨
#plants⚡#adaptation⚡#resilience
👉subscribe Interesting Planet
🌍 Some coral reefs in the Red Sea host unique fish and coral species that can tolerate extreme heat and high salt levels, making them among the most resilient reef ecosystems on Earth. ✨
#coral⚡#marine⚡#resilience⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
Ad Al-Wafa, a Gaza, questa settimana si è celebrata la cerimonia di fine anno scolastico per migliaia di bambini.
Un evento che in condizioni normali sarebbe stato occasione di festa ma che si è trasformato in un momento intriso di dolore. I volti dei piccoli brillavano d’orgoglio mentre ricevevano i diplomi ma dietro ai sorrisi si nascondeva un vuoto profondo: nessun genitore ad applaudirli, nessuno a scattare foto o a sussurrare parole di incoraggiamento.
Un rapporto dell’ONU rivela che oltre il 90 % delle scuole e università sono state danneggiate o distrutte, privando dell’istruzione più di 800.000 bambini e ragazzi e interrompendo la vita accademica di circa 90.000 universitari. Oggi tutti questi ragazzi studiano in tende di fortuna gestire da Unicef, ONU E UNRWA continuamente bersagliate dall’artiglieria di Israele.
#gazagenocide#gazastudents#resilience
🌎 Trapped under debris for 17 days after a 2015 Nepal earthquake, Pemba Tamang survived by drinking muddy water dripping from rubble and eating small snacks. He emerged with only minor injuries after nearly 2½ weeks underground, making it one of the longest earthquake survival cases recorded. ✨
#survival⚡#earthquake⚡#resilience
👉subscribe Interesting Planet
👉more Channels
🌎 The tardigrade’s cousin, the rotifer, can survive drying out for decades by entering a state called cryptobiosis. When water returns, it wakes up as if nothing happened, showing remarkable resilience in the micro-world. ✨
#rotifer⚡#cryptobiosis⚡#resilience
👉subscribe Interesting Planet
As the 60-day ceasefire deadline ended, the people of southern #Lebanon returned to their homes despite Israeli violence. 15 martyrs and 83 injured in the ongoing struggle for their land.
#DayOfReturn#CeasefireDeadline#Resilience#Israel#SouthernLebanon#Occupation
After over a year of displacement, the people of southern #Lebanon return—not to homes, but to the land scarred by Israeli aggression. Their spirit is unbroken.
#Resilience#SouthernLebanon#ReclaimingHome#Rebuilding#Israel#LebaneseArmy
🚀 South Korea's Central Bank Governor: Export Performance Exceeds Expectations
South Korea's central bank governor, Lee Chang-yong, has stated that the country's export performance has surpassed expectations. According to Jin10, Lee highlighted the positive export figures during a recent address, noting that the results are better than initially anticipated. This development comes amid ongoing global economic challenges, where South Korea's export sector has shown resilience and adaptability. The improved export performance is seen as a crucial factor in supporting the nation's economic stability and growth. Lee's remarks underscore the importance of exports in South Korea's economic strategy, as the country continues to navigate complex international trade dynamics.
#SouthKorea#CentralBank#ExportPerformance#EconomicGrowth#GlobalEconomy#Resilience#TradeDynamics#LeeChangYong#EconomicStability
When kids have big emotions, we tend to think they are being overly sensitive, that they need more resilience. Most of the time it is because there is a lot happening for the child that we can't see and don't know, that is pushing them beyond their means of coping. Instead we can change the response from they are overreacting, to seeing a child who has a lot happen for them, they are doing the best they can. They need our help not judgement.
#parenting#positiveparenting#gentleparenting#resilience#respectfulparenting#psychologist#play#playtherapy#childdevelopment#childtherapy#parentingtips#teachers#asd#family#life#adhd#mumlife#momlife#dads#consciousparenting
https://www.instagram.com/p/Ctd93W8vEM9/