Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
The average lifespan of a goldfish (Carassius auratus) is 10-15 years, with some varieties living into their thirties when properly cared for.
However, one male goldfish named Tish (1956-1999) lived to the remarkable age of 43, making him the world’s oldest goldfish ever.
[Read more]
@googlefactss
#FunFact#AnimalFacts#fish
Male llamas grow sharp canines called ‘fighting teeth’ that they use to show who's boss and settle disputes with other males. @googlefactss#Llamas#AnimalFacts#Nature🦙🦷
Cats have three types of color-detecting cones, just like humans, but see colors less vividly. They perceive blues and greens well, but reds and pinks may appear grayish. Their vision excels at detecting subtle movement, especially in dim light. 🔵🟢🌙
[Read more]
[See here]
@googlefactss#CatVision#AnimalFacts#Science
Beavers build dams to protect themselves from predators like bears and wolves. They live in lodges, not in the dam itself, on deep ponds made by the dams. These lodges have underwater entrances, so beavers can safely enter and leave without being seen. The pond keeps land animals away and the lodge is a dry home and food storage. 🦫🌊🌿@googlefactss#Beavers#Wildlife#Nature#AnimalFacts
Llamas spit to protect themselves, keep their place, or show power. Males spit in fights over females. Females spit to stop males. They also spit when annoyed or mistreated. Llama spit has saliva and partly digested food. It can fly up to 10 meters (33 feet). 🦙💨
[Source]
@googlefactss#Llamas#AnimalFacts#Spitting
Penguins have several group names. A group in water is called a “raft.” On land, it is called a “waddle.” A large group of penguins living or breeding together is called a “colony.” The place where they gather to breed is also called a “rookery.”
🐧🌊🏝️🐣
[Read more]
@googlefactss
#Penguins#AnimalFacts#Wildlife#DidYouKnow
Elephants can “listen” with their feet. Their foot pads have special nerve receptors that detect ground vibrations, including very low-frequency infrasound. Vibrations from other elephants’ rumbles or footsteps travel through the ground. Signals move through their bodies to the brain. Vibrations can also reach the inner ear through bone conduction. This helps elephants communicate over long distances and sense distant movement.
🐘🌍👣🔊
[Read more]
@googlefactss
#Elephants#AnimalFacts#Wildlife#Nature#Science#DidYouKnow
Hippos secrete red oily "blood sweat" that protects their skin from sun and germs. It keeps their skin moist and healthy.
🦛☀️
[Read more]
@googlefactss
#Hippos#AnimalFacts#Nature#Wildlife#SunProtection
🐾 Capybaras are the world's largest rodents — social, semi-aquatic animals that live in groups in South America. They're so calm that other animals often sit on them, and they can even sleep underwater! 🌊
[Learn more]
@googlefactss#Capybara#AnimalFacts#Nature#Rodents#Wildlife
Whale sharks have tiny teeth covering their eyeballs. 🦈👁️
These "dermal denticles" act like protective armor for their protruding, lidless eyes.
[Source]
@googlefactss#AnimalFacts#Sharks#MarineBiology#NatureIsWild
Snow leopards are sometimes seen biting or holding their own tails. Scientists think they may do this to stay warm in cold mountain habitats or to play. A snow leopard’s long, thick tail also helps it balance on steep rocky cliffs and can wrap around its body like a blanket.
🐆❄️🐾
[Read more 1]
[Read more 2]
@googlefactss
#snowleopard#animalfacts#wildlife#naturefacts#bigcats#didyouknow