Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
On 9 June, International Archives Day is celebrated around the world. Often these documents are classified for decades. Only the next generation can learn about the reasons and details of the event in a reliable way.
Our post is about the nuclear bombing of Hiroshima, which American President Harry Truman advocated. The declassified archives make it clear the bombing of Japan was to be a rehearsal for a possible nuclear war between the US and the USSR. Watch the entire film Atomic Message for details.
#history#disasters
Follow: https://t.me/rtdocumentary
🌎 A colossal tsunami struck Japan’s Sanriku coast in 1896, triggered by an undersea earthquake. Towering waves up to 38 meters high destroyed villages and claimed nearly 22,000 lives, prompting global advances in seismic and tsunami warning systems. ✨
#tsunami⚡#history⚡#disasters
👉subscribe Interesting Planet
🌎 At the heart of Africa, Lake Nyos hides a deadly secret—an underwater layer of carbon dioxide gas that once erupted, suffocating everything nearby in 1986. This rare “limnic eruption” happens when gas builds up at depth and suddenly bursts to the surface, releasing an invisible, odorless cloud with devastating effects. ✨
#volcanoes⚡#disasters⚡#geology
👉subscribe Interesting Planet
🌍 In 2022, two major floods in Pakistan covered about one-third of the country, displacing over 33 million people—one of the largest human impacts from a single natural disaster this decade. ✨
#disasters⚡#flooding⚡#climate⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In 2021, a record-breaking heatwave in western Canada triggered hundreds of wildfires, generating so much smoke it traveled thousands of kilometers and reached northern Europe. ✨
#disasters⚡#wildfires⚡#climate⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 In 2021, Europe's Aegean wildfires generated smoke that reached as far as the North Pole—a rare journey showing how natural disasters can have effects thousands of kilometers away. ✨
#disasters⚡#wildfire⚡#atmosphere⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 The Tonga eruption in 2022 sent shockwaves around the globe so powerful they circled Earth several times. Its volcanic plume was the tallest ever recorded, reaching almost 58 kilometers high. ✨
#volcano⚡#eruption⚡#disasters⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Earth’s largest volcanic eruption in the past 70,000 years was Toba in Indonesia. Its explosion formed a lake-filled crater 100 kilometers wide and sent ash around the globe. ✨
#disasters⚡#volcano⚡#eruption⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Tornado Alley in the central United States experiences more tornadoes than anywhere else on Earth. Warm and cold air mix here, making intense storms common each spring and early summer. ✨
#tornadoes⚡#storms⚡#disasters⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 Super Typhoon Haiyan in 2013 set a record for the strongest tropical cyclone to make landfall, with winds reaching 315 km/h. Its extreme force reshaped entire coastlines in the Philippines. ✨
#disasters⚡#typhoon⚡#wind⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 The 2018 Sulawesi earthquake in Indonesia triggered a rare "soil liquefaction," turning solid ground into a flowing sludge that swallowed entire neighborhoods beneath muddy waves. ✨
#disasters⚡#earthquake⚡#liquefaction⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 The 2004 Indian Ocean tsunami sent waves up to 30 meters high across 14 countries. This natural disaster traveled as fast as a jet plane, reaching Africa in mere hours. ✨
#tsunami⚡#disasters⚡#waves⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍