Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
Embark on a journey of progress and transformation! 🚀
Visit https://9years.mygov.in/ to discover the incredible achievements of the Modi Government in the last 9 years. Explore the remarkable strides made across various sectors, from healthcare to infrastructure, education to governance.
#9YearsOfSeva
🇮🇳 In 9 years, the Modi Government achieved an unprecedented combination of speed and scale, ensuring the timely completion of all projects!
From highways and airports to digital infrastructure, India witnessed an era of efficient governance that propelled progress at an unmatched pace.
#9YearsOfSeva
https://youtu.be/L7x-8aIjSQ0
"सेवा, सुशासन और गरीब कल्याण को सर्मपित 9️⃣ साल" 🇮🇳
आइए इस वीडियों के माध्यम से देखें कैसे, बीते 9 वर्षों में #NewIndia जनसामान्य की आकांक्षाओं को पूरा करते हुए निरन्तर नई-नई उपलब्धियां रच रहा है।
#9YearsOfSeva
https://youtu.be/L7x-8aIjSQ0
"सेवा, सुशासन और गरीब कल्याण को सर्मपित 9️⃣ साल" 🇮🇳
आइए इस वीडियों के माध्यम से देखें कैसे, बीते 9 वर्षों में #NewIndia जनसामान्य की आकांक्षाओं को पूरा करते हुए निरन्तर नई-नई उपलब्धियां रच रहा है।
#9YearsOfSeva
https://youtu.be/L7x-8aIjSQ0
बीते 9 वर्षों में माननीय प्रधानमंत्री #NarendraModi के नेतृत्व में केंद्र सरकार द्वारा विभिन्न क्षेत्रों में हुई अविश्वसनीय उपलब्धियों को जानने हेतु अभी विजिट करेः https://9years.mygov.in/
#9YearsOfSeva
Don't miss this remarkable video showcasing how the Modi government's relentless efforts over the past 9 years have propelled the development and preservation of India's rich cultural heritage.
Visit: https://youtu.be/scGbw2m8ook
#9YearsOfPreservingCulture
#9YearsOfSeva
Check out this captivating snapshot showcasing the Modi government's remarkable progress in preserving and promoting India's cultural heritage. From restoring ancient monuments to revitalizing traditional arts, their efforts over the past 9 years have made India's legacy shine brighter than ever.
#9YearsOfPreservingCulture
#9YearsOfSeva
📈 India keeps dominating the digital payment landscape! 💸🇮🇳 With innovative solutions and widespread adoption, we're leading the way towards a cashless economy. 💻
#9YearsOfTechForGrowth#9YearsOfSeva
Empowering street vendors for a brighter future!
PM SVANidhi is transforming lives & livelihoods, providing financial support, & fostering entrepreneurship among street vendors in India
#9YearsOfGaribKalyan#9YearsOfSeva
Check out this captivating snapshot showcasing the incredible strides made in environment and sustainability during the 9 years of the Modi government.
#9YearsOfSustainableGrowth#9YearsOfSeva