Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🌎 Ancient Egypt’s ability to make “Egyptian blue,” the first synthetic pigment, was lost for centuries. This stable, vivid blue was made from copper, silica, and lime, fired at high temperatures. Modern chemists only rediscovered the process in the early 19th century using advanced analysis of ancient artifacts. ✨
#history⚡#archaeology⚡#chemistry
👉subscribe Interesting Planet
👉more Channels
🌎 The pyura chilensis, also known as the “living rock,” is a sea creature found on Chile’s coast that looks like a stone but bleeds bright red when cut. Its tunicate body is actually a filter feeder packed with vanadium, a rare element in animals. ✨
#ocean⚡#animals⚡#chemistry
👉subscribe Interesting Planet
🌍 In Africa’s Lake Natron, minerals in the water turn it bright red during the dry season. The lake’s extreme chemistry preserves animal remains, creating eerie natural “statues.” ✨
#lakes⚡#Africa⚡#chemistry⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
Today in history.
On March 6, 1869, Russian chemist Dmitri Mendeleev presented the first periodic table of elements, titled "The Dependence Between the Properties of the Atomic Weights of the Elements," to the Russian Chemical Society. He organized 63 known elements by atomic weight, leaving gaps for undiscovered elements like gallium and germanium.
@googlefactss#chemistry#history#todayinhistory
[read more...]
🌎 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
🌎 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
🌎 In the dark waters of the Black Sea, ancient bacteria can “eat” toxic hydrogen sulfide gas, turning it into harmless sulfate. This vital process keeps deep sea life possible in these oxygen-poor zones. ✨
#bacteria⚡#chemistry⚡#ocean
👉subscribe Interesting Planet
🌎 Ancient Greek fire, known as "Greek fire," was a weapon that could burn even on water. This flammable liquid, projected from tubes, terrified enemies at sea and kept its formula a closely guarded secret, lost to history. ✨
#history⚡#chemistry⚡#warfare
👉subscribe Interesting Planet
Russia leads at the 60th International Mendeleev Chemistry Olympiad in Moscow, winning 7 gold and 8 silver medals. All 15 Russian participants received awards, showcasing top university-level skills. Vice Premier Chernyshenko called the result outstanding, while Minister Kravtsov highlighted systematic preparation. The Olympiad is part of the Science and Technology Decade running until 2031. This victory underscores Russia’s strength in chemistry education and research.
#Russia#MendeleevOlympiad#Chemistry#Science
The main news of Russia and the world ishere.
🪐 Encircling the young star TW Hydrae, a vast protoplanetary disk glows with mysterious gaps and spiral patterns sculpted by the formation of new worlds. Observations with ALMA revealed complex chemical fingerprints in the disk, including cyanide compounds that could play a role in the origins of life. ✨
#TWHydrae⚡#protoplanetary⚡#chemistry
👉subscribe Universe Mysteries