Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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 invention of the safety elevator by Elisha Otis in 1852 made skyscrapers possible. His design featured a locking mechanism that stopped the elevator if the hoisting cable snapped. Otis demonstrated this life-saving device at the 1854 World’s Fair in New York, boosting public trust in elevators. ✨
#inventions⚡#history⚡#engineering
👉subscribe Interesting Planet
👉more Channels
🌎 X-rays were discovered accidentally in 1895 by German physicist Wilhelm Röntgen. While experimenting with cathode rays, he noticed an unknown radiation that could pass through solids and reveal images of bones. Today, X-rays are a key tool in medicine and industry worldwide. ✨
#inventions⚡#history⚡#physics
👉subscribe Interesting Planet
👉more Channels
🌎 The invention of the modern stethoscope in 1816 by French physician René Laennec transformed medical diagnosis. By rolling paper into a tube, Laennec could hear internal chest sounds clearly, improving detection of lung and heart conditions. The first stethoscopes were made of wood and about 25 centimeters long. ✨
#history⚡#medicine⚡#inventions
👉subscribe Interesting Planet
👉more Channels
🌎 In 1867, Swedish chemist Alfred Nobel invented dynamite by stabilizing volatile nitroglycerin with an absorbent clay called kieselguhr. This made blasting much safer for construction and mining. Nobel later used his dynamite fortune to establish the Nobel Prizes in 1895. ✨
#inventions⚡#chemistry⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 In 1903, the Wright brothers achieved the first powered, controlled, and sustained flight of an airplane at Kitty Hawk, North Carolina. Their aircraft, the Wright Flyer, flew for 12 seconds and covered 36 meters. ✨
#inventions⚡#aviation⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 The accidental invention of safety glass happened in 1903, when French chemist Édouard Bénédictus dropped a glass flask coated with plastic cellulose nitrate. Rather than shattering, the glass cracked but held together, inspiring shatter-resistant windshields. By 1927, safety glass became standard in automobile manufacturing. ✨
#inventions⚡#chemistry⚡#history
👉subscribe Interesting Planet
👉more Channels
The first vending machine was invented in the 1st century AD by Greek engineer Heron of Alexandria. It dispensed holy water when a coin was inserted—the weight tilted a lever, opening a valve to release water before the coin dropped. 💧⚖️
[Learn more]
@googlefactss
#History#Inventions#Engineering#AncientGreece
Professor Muhammed Uvaze ixtirolari Buyuk Britaniyada patentlashtirilgani haqida Hudud informatsion dasturida lavha tayyorlandi.
#hudud#patent#inventions
⬇️Biz ijtimoiy tarmoqlarda:
Veb-sayt | Telegram | Instagram | Facebook
🌎 The discovery of radioactivity in 1896 by Henri Becquerel revealed that uranium salts emit invisible energy. This led to the identification of new elements like polonium and radium by Marie and Pierre Curie. Their work contributed to the development of X-ray machines and atomic science. The Curies isolated just 1 gram of radium from 8 tons of ore. ✨
#radioactivity⚡#discovery⚡#inventions
👉subscribe Interesting Planet
🌀💦 South African Invention That Changed Pool Life
Did you know the automatic pool cleaner was invented in 🇿🇦 South Africa?
👨🔧 In 1974, hydraulics engineer Ferdinand Chauvier (pictured), who had moved from the Belgian Congo to South Africa, came up with a way to take the hassle out of pool cleaning.
The result? The legendary Kreepy Krauly — one of the very first automatic pool cleaners, designed and built in Springs, South Africa. 🌍✨
His invention made pools around the world easier to maintain — and became a proudly South African contribution to everyday comfort.
🏊♂️ From Johannesburg to Los Angeles, millions of pools have been cleaned thanks to Chauvier’s idea.
#Inventions#SouthAfrica#Innovation#KreepyKrauly#History#MadeInSA