Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
Cholesterol protects the integrity of cell membranes and keeps cells healthy and strong. If a person’s cholesterol level were 0 (an impossibility), his cell membranes would be dry and cracked and all the cell content would leak out.
@googlefactss#humanbody
For most women (about 65%), the left breast is bigger than the right one. Researchers are unsure why, but they point to hormonal influences during development.
@googlefactss#humanbody
A human spinal cord stops growing in length around age four or five, while the vertebral column (spine) continues to grow until late adolescence or early adulthood.
@googlefactss#humanbody
In a condition called pelvic prolapse, a woman’s vagina can literally fall out and hang between the legs. Pelvic prolapse, however, can often be fixed..
@googlefactss#humanbody
[read more...]
The same skin cells that make up a human vagina are the same type of cells that are in a human mouth. The nonkeratinized stratified squamous epithelium are types of mucous membranes that are sensitive, absorbent, and continuously shed and regenerated.
@googlefactss#humanbody
It is common and normal for mothers to poop while giving birth. This often happens during the pushing stage because the muscles used to push a baby out are the same ones used to have a bowel movement.
@googlefactss#humanbody#nowyouknow
Occasionally, human corpses can undergo saponification, a process in which body fat transforms into adipocere through a chemical reaction. Adipocere has a consistency similar to semi-hard cheese and possesses a soapy feel. The most well-known example of this phenomenon is the "Soap Lady," a 140-year-old mummy showcased in Pennsylvania.
@googlefactss#humanbody#nowyouknow
Myth: The tongue is divided up into specific areas that are solely responsible for sensing certain tastes (e.g., sweet at the tip, bitter at the back)
Fact: The tongue's receptor cells that identify the molecules underlying the basic tastes (sweet, sour, salt, bitter and umami) are distributed on taste buds all over the tongue although some areas may be slightly more sensitive to certain flavors..
@googlefactss#humanbody#nowyouknow#mythbusted
[read more...]
Fingernail facts:
The middle finger’s nail grows the fastest while the smallest finger’s grows the slowest.
Nails usually grow faster on your dominant or more active hand (more use → more repair → more blood/nutrients) and speed up in summer thanks to better circulation.
Toenails grow slower.
Overall, males’ nails often grow faster than females’, but during puberty and pregnancy higher hormone levels make nails grow quicker in women.
[Source]
@googlefactss
#FunFact#HumanBody#nails