Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🌎 Entering the massive Krubera Cave in Georgia is like descending into another world—at over 2,197 meters deep, it’s the deepest known cave on Earth. These underground labyrinths feature rivers, waterfalls, and unique blind creatures, revealing entire ecosystems hidden from sunlight. ✨
#geology⚡#caves⚡#ecosystems
👉subscribe Interesting Planet
🌎 From blazing deserts to frozen poles, Earth's extreme climate zones push life to its limits. In polar regions, temperatures plunge below -50°C, creating icy landscapes where only the hardiest animals, like penguins and polar bears, survive. Meanwhile, equatorial deserts like the Sahara reach scorching highs over 50°C, supporting unique plants and animals adapted to relentless heat. These climate extremes shape our planet’s most remarkable ecosystems and inspire some of nature’s wildest survival strategies. ✨
#climate⚡#ecosystems⚡#adaptation
👉subscribe Interesting Planet
🌍 The Serengeti savanna in Africa hosts one of the world’s largest mammal migrations—zebras cross first, followed by wildebeest, each group timing their journey to feed on different heights of grass. ✨
#savanna⚡#migration⚡#ecosystems⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Africa’s Miombo savanna covers over 2.7 million square kilometers—about the size of Argentina. Its woodlands support hundreds of unique butterfly species found nowhere else on Earth. ✨
#savanna⚡#grasslands⚡#ecosystems⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌎 Hidden off the Pacific coast of California, the Point Dume Submarine Canyon plunges over 800 meters deep just a short distance from shore. Scientists have discovered mysterious methane seeps and rare deep-sea corals within the canyon. These underwater features support unique ecosystems not found anywhere else nearby. ✨
#ocean⚡#canyon⚡#ecosystems
👉subscribe Interesting Planet
👉more Channels
🌎 Some bamboo species can grow up to 91 centimeters in a single day, making bamboo one of the fastest-growing plants on Earth. This rapid growth helps bamboo quickly regenerate after being harvested and provides vital habitats for many animals. ✨
#botany⚡#speed⚡#ecosystems
👉subscribe Interesting Planet
🌎 Deep in the Congo Basin, the African rainforest elephant forges secret trails through dense jungle, creating “elephant highways” that other animals use. These hidden paths help shape entire forest ecosystems by opening routes for seed dispersal and wildlife movement. ✨
#rainforest⚡#elephants⚡#ecosystems
👉subscribe Interesting Planet
🌍 Submarine hydrothermal vents on the ocean floor release superheated water and minerals, fueling unique ecosystems powered by chemical energy instead of sunlight. ✨
#processes⚡#ocean⚡#ecosystems⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌎 In the dry canyons of the American Southwest, cryptobiotic soil forms a living crust of bacteria, fungi, and lichens. This fragile layer stabilizes desert soil and helps seeds germinate, supporting entire ecosystems in these harsh climates. ✨
#desert⚡#microbiology⚡#ecosystems
👉subscribe Interesting Planet
🌍 Some deep-water corals build reefs in cold, dark oceans thousands of meters below the surface. Unlike tropical reefs, these cold-water reefs thrive without sunlight or warm water. ✨
#coral⚡#marine⚡#ecosystems⚡#ocean⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 The highest forests on Earth grow above 4,900 meters in the Andes, where trees survive thin air, cold temperatures, and strong sunlight—an extreme zone where biosphere meets atmosphere and lithosphere. ✨
#spheres⚡#Andes⚡#ecosystems⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌎 The tuco-tuco, a South American rodent, lives almost its entire life underground. It digs vast tunnel networks with specialized teeth, rarely surfacing except to gather food. Its burrowing helps aerate soil, making tuco-tucos quiet but essential ecosystem engineers. ✨
#rodents⚡#ecosystems⚡#burrowing
👉subscribe Interesting Planet