Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
An elephant’s trunk 🐘 is an amazing example of evolutionary development 🧬. It is a combined nose and upper lip that lengthened as the elephant’s ancestors became taller and their tusks grew bigger. With its heavy head, it needed an easy way to reach the ground.
@googlefactss#evolution
Автопортреты Joni Mitchell, которые стали обложками её релизов
• Clouds
• Ladies Of The Canyon
• Wild Things Run Fast
• Turbulent Indigo
• Taming The Tiger
• Both Sides Now
• Travelogue
• Dreamland
• The Reprise Albums (1968-1971)
Митчелл часто говорила, что она «художник, который выпускает песни».
Нельзя не заметить очевидную отсылку на другого художника, который за жизнь нарисовал с десяток автопортретов, — Винсента Ван Гога с отрезанным ухом на обложке «Turbulent Indigo».
#evolution
🌍 The island of New Caledonia is a biodiversity hotspot where ancient plants like the rare Amborella tree represent some of Earth’s oldest surviving flowering lineages, found nowhere else. ✨
#biodiversity⚡#islands⚡#evolution⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌎 The star-nosed mole detects prey in total darkness using its unique nose, covered in 22 finger-like tentacles packed with touch sensors. This extraordinary adaptation lets it identify and eat tiny insects and worms faster than any other mammal, even underwater. ✨
#animals⚡#adaptation⚡#evolution
👉subscribe Interesting Planet
🌎 The saiga antelope’s enlarged, drooping nose acts as a built-in air filter and cooler on the Central Asian steppes. When alarmed, herds can stampede at speeds up to 80 kilometers per hour. ✨
#animals⚡#evolution⚡#biodiversity
👉subscribe Interesting Planet
👉more Channels
🌎 The shoebill stork stands over 1.2 meters tall and has a massive, shoe-shaped bill up to 24 centimeters long. Native to East African swamps, this solitary bird hunts lungfish, frogs, and even baby crocodiles. ✨
#animals⚡#biodiversity⚡#evolution
👉subscribe Interesting Planet
👉more Channels
🌎 The platypus baffles scientists as it lays eggs like a reptile but produces milk and has fur like a mammal—a rare mix found in no other living animal. This odd, Australian creature even senses prey underwater using electroreceptors in its bill. ✨
#animals⚡#evolution⚡#Australia
👉subscribe Interesting Planet
🌎 Horseshoe crabs have remained virtually unchanged for about 450 million years. Despite their name, they are more closely related to spiders than to true crabs. Modern horseshoe crabs can be found along the Atlantic coast of North America and in Southeast Asia. ✨
#animals⚡#evolution⚡#fossils
👉subscribe Interesting Planet
👉more Channels
🌎 Living fossils like the chambered nautilus and horseshoe crab have changed little for hundreds of millions of years. The nautilus dates back over 500 million years, and its closest extinct relatives include ammonites, which died out with the dinosaurs. ✨
#evolution⚡#fossils⚡#animals
👉subscribe Interesting Planet
👉more Channels
🌎 Living fossils like the giant freshwater stingray and the Australian lungfish have remained almost unchanged for over 100 million years, surviving dramatic changes in Earth’s environment. The horseshoe crab’s body plan is so ancient, it first appeared 450 million years ago. ✨
#evolution⚡#fossils⚡#animals
👉subscribe Interesting Planet
👉more Channels
🌎 Some ancient animals have survived unchanged for millions of years. The coelacanth, once thought extinct, first appeared 400 million years ago and still swims deep ocean waters today. The horseshoe crab dates back over 450 million years, predating dinosaurs and even trees. ✨
#evolution⚡#fossils⚡#animals
👉subscribe Interesting Planet