Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🌎 Deep in southeastern Iran, the mysterious Kaluts desert features gigantic, wind-carved sand formations called “yardangs.” These natural sculptures stretch for kilometers, shaped by centuries of relentless wind erosion. ✨
#geology⚡#desert⚡#landscapes
👉subscribe Interesting Planet
🌎 Powerful enough to move mountains, glaciers shaped entire continents. As they advanced, their slow, grinding ice carved out valleys, lakes, and fjords still visible today. ✨
#geology⚡#glaciers⚡#landscapes
👉subscribe Interesting Planet
🌎 Southern China’s Stone Forest, or Shilin, is a dramatic landscape of towering limestone pillars shaped by both natural erosion and centuries of quarrying. Human mining over the last thousand years has altered parts of this ancient karst region, creating new rock formations and open spaces alongside original spires. ✨
#geology⚡#humanimpact⚡#landscapes
👉subscribe Interesting Planet
👉more Channels
🌍 The Rice Terraces of Yuanyang in China were carved into steep mountains over centuries. These living heritage sites are so vast they create their own microclimate and reflect the region's cultural history. ✨
#heritage⚡#landscapes⚡#agriculture⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 The geographic shell of the Earth includes plateaus, plains, and mountain ranges, creating a patchwork that determines where rivers flow and where different climates form. ✨
#landforms⚡#climate⚡#landscapes⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 In Japan, centuries-old forest areas called satoyama are shaped by human care for farming, wood, and water, blending wild nature and villages into landscapes rich in biodiversity and tradition. ✨
#interaction⚡#landscapes⚡#biodiversity⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Some arid desert landscapes feature ancient, dried-up riverbeds called wadis that can flood suddenly after rare rains, quickly turning from bare channels to rushing streams in a matter of hours. ✨
#desert⚡#arid⚡#landscapes⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In Indonesia, ancient forests and rice terraces share land with villages, blending wild and human-shaped environments. This mix supports rare wildlife while feeding local communities. ✨
#interaction⚡#landscapes⚡#sustainability⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In China's southern hills, vast terraces transform mountains into rice fields. These hand-carved steps let farmers grow crops high above valleys, creating some of the world’s most scenic farmland. ✨
#agriculture⚡#landscapes⚡#rice⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Italy’s Cinque Terre is a World Heritage Site where human-built terraced vineyards cling to steep cliffs beside the sea. Centuries of farming have shaped this landscape into a living cultural mosaic. ✨
#heritage⚡#landscapes⚡#vineyards⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 England’s Lake District is a UNESCO World Heritage Site where centuries of sheep farming shaped rolling hills and stone walls, blending natural scenery with a rich cultural landscape. ✨
#heritage⚡#landscapes⚡#UNESCO⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍