Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🌎 Glowing deep-sea animals like the comb jellyfish and dragonfish create their own light using bioluminescence. This adaptation helps them hunt, attract mates, or avoid predators in pitch-black ocean depths. Some dragonfish possess "invisible" red bioluminescence, seen only by their own kind, for stealthy communication. ✨
#ocean⚡#animals⚡#bioluminescence
👉subscribe Interesting Planet
👉more Channels
🌍 The Waitomo Glowworm Caves in New Zealand are famous for thousands of tiny insects that light up the darkness, creating a galaxy-like effect in this unique karst underground world. ✨
#caves⚡#karst⚡#bioluminescence⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌎 Shrouded in darkness, the “midnight zone” of the ocean lies below 1,000 meters, where sunlight can’t reach and pressure crushes like a dozen elephants. Creatures here glow with bioluminescence and withstand freezing cold, revealing how life adapts to our planet’s most mysterious depths. ✨
#ocean⚡#bioluminescence⚡#deepsea
👉subscribe Interesting Planet
🌎 Lightning bugs, or fireflies, create their glow through a special enzyme called luciferase. This reaction produces cold light, wasting almost no energy as heat—a marvel of natural engineering for nighttime signaling. ✨
#bioluminescence⚡#insects⚡#nature
👉subscribe Interesting Planet
🌎 Glowing tides known as bioluminescent bays light up in places like Puerto Rico. Microorganisms called dinoflagellates produce blue-green light when stirred by waves or movement. The brightest, Mosquito Bay, can host up to 700,000 glowing organisms in just one liter of water. ✨
#bioluminescence⚡#ocean⚡#phenomenon
👉subscribe Interesting Planet
👉more Channels
🌍 Some coasts shine with glowing “blue waves” at night, caused by tiny plankton called dinoflagellates emitting light when disturbed—a dazzling phenomenon known as marine bioluminescence. ✨
#seas⚡#coastline⚡#bioluminescence⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌎 Glowing waves known as “sea sparkle” can light up coastlines at night. This effect is caused by bioluminescent plankton emitting blue light when disturbed. Some blooms stretch for kilometers and are most often seen in warm coastal waters. ✨
#bioluminescence⚡#ocean⚡#plankton
👉subscribe Interesting Planet
👉more Channels
🌎 Glowing waves sometimes light up the ocean at night thanks to bioluminescent plankton. These tiny marine organisms emit blue light when disturbed, turning shorelines into breathtaking, natural light shows. ✨
#ocean⚡#bioluminescence⚡#plankton
👉subscribe Interesting Planet
🌎 The vampire squid thrives in the ocean’s dark depths by using bioluminescent light organs to confuse predators. Its name comes from its cloak-like webbed arms, not from blood-drinking. ✨
#ocean⚡#cephalopod⚡#bioluminescence
👉subscribe Interesting Planet
🌎 In the Mediterranean Sea, the bearded fireworm boasts bristly, glowing spines that can cause a painful sting. This marine worm’s bioluminescence warns predators while its venomous bristles deter unwelcome touches—a perfect example of nature’s flashy, double-edged defense system. ✨
#fireworm⚡#bioluminescence⚡#ocean
👉subscribe Interesting Planet
🌎 Somewhere in the world’s oceans, the “milky sea” phenomenon can make water glow bright blue for up to several days. Caused by massive colonies of bioluminescent bacteria, these rare glowing patches can cover areas larger than 15,000 square kilometers—visible even from space. ✨
#ocean⚡#mysteries⚡#bioluminescence⚡#bacteria
👉subscribe Interesting Planet