Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🪐 Just 12 light-years away, the red dwarf star Teegarden’s Star hosts two Earth-sized exoplanets, Teegarden’s Star b and c, both located in the star’s habitable zone. This zone is the area around a star where temperatures could allow liquid water to exist—a key ingredient for life as we know it—making these planets some of the most intriguing nearby candidates in the search for life beyond our solar system. ✨
#exoplanets⚡#habitablezone⚡#astrobiology⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The exoplanet K2-18b, located about 120 light-years away in the constellation Leo, has been found to possess water vapor in its atmosphere—making it one of the few known exoplanets within its star’s habitable zone where conditions might allow liquid water. K2-18b is a "mini-Neptune," meaning it’s larger than Earth but smaller than Neptune, and its potential for moderate temperatures and watery clouds raises the possibility that life-friendly environments could exist beyond our solar system. ✨
#exoplanets⚡#life⚡#habitablezone⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Deep in the constellation Aquarius, astronomers have discovered exoplanet K2-72e orbiting a cool red dwarf star roughly 227 light-years from Earth. K2-72e is a rocky world located within its star’s habitable zone—the region where temperatures might allow liquid water on the surface—making it another intriguing candidate in the search for planets that could support life beyond our solar system. ✨
#exoplanets⚡#habitablezone⚡#discovery⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Astronomers have identified Proxima Centauri b, an Earth-sized exoplanet orbiting the closest star to our Sun, as one of the nearest spots where life could possibly exist. Sitting in its star's "habitable zone"—the region where temperatures might allow liquid water—this world offers a natural laboratory to explore the potential for life beyond our solar system. ✨
#exoplanets⚡#habitablezone⚡#discovery⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The exoplanet TOI-700 d, orbiting a small, cool star about 101 light-years away in the constellation Dorado, lies within its star’s “habitable zone,” where temperatures might allow water to exist as a liquid on the surface. This rocky world is similar in size to Earth and is one of the few confirmed planets outside our solar system where scientists believe the conditions could be just right for life as we know it to survive. ✨
#exoplanets⚡#habitablezone⚡#dorado⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Over 42 light-years from Earth, the exoplanet Tau Ceti e orbits within the habitable zone of its Sun-like star—meaning it receives just the right amount of energy that could allow liquid water to exist on its surface. While Tau Ceti e is about 60% larger than Earth and its true environment remains a mystery, its location around one of our closest stellar neighbors makes it a real and intriguing candidate in the search for life beyond our solar system. ✨
#exoplanets⚡#habitablezone⚡#lifebeyondearth⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Astronomers have identified the exoplanet Wolf 1069 b, located about 31 light-years away in the constellation Cygnus, as a promising place where life could exist. This rocky planet orbits in its star's habitable zone—the region where temperatures may allow liquid water to pool on the surface—making it one of the most intriguing nearby candidates in the search for life beyond our solar system. ✨
#exoplanets⚡#habitablezone⚡#wolf1069b⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries