Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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 galaxy NGC 2683, sometimes called the "UFO Galaxy," has a dramatic, warped disk that gives it a shape unlike typical spirals. Located about 35 million light-years away in the constellation Lynx, its tilted, edge-on view and slightly twisted arms create the illusion of a flying saucer drifting through space, making it one of the most striking examples of galaxies with unusual forms. ✨
#galaxies⚡#shapes⚡#astronomy⚡#nasa⚡#galaxy⚡#stars⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The galaxy NGC 4710, located about 60 million light-years away in the constellation Coma Berenices, is famous for its strikingly thin, edge-on profile that makes it look more like a cosmic needle than a typical spiral or elliptical galaxy. This unusual "boxy/peanut-shaped" bulge is thought to form when a flat disk of stars buckles and warps over time, creating a rare structure that reveals the hidden dynamics shaping galactic evolution. ✨
#galaxies⚡#shapes⚡#astronomy⚡#nasa⚡#galaxy⚡#stars⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The galaxy UGC 2885, sometimes called "Rubin's Galaxy," sports an unusual appearance with its outsized, sprawling disk—nearly 2.5 times wider than the Milky Way. Its vast, faint spiral arms stretch for over half a million light-years, making it not only one of the largest known spiral galaxies but also a cosmic oddity that challenges ideas about how galaxies can grow and maintain such immense, delicate structures. ✨
#galaxies⚡#mysteries⚡#shapes⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The galaxy known as the Cartwheel Galaxy, located about 500 million light-years away in the constellation Sculptor, displays a striking ring-and-spoke structure unlike ordinary spirals or ovals. Its unusual shape was created when a smaller galaxy crashed through its center, sending waves of star formation racing outward and leaving behind bright, circular rings and faint, radial arms—an extraordinary cosmic ripple frozen in space. ✨
#galaxies⚡#shapes⚡#collisions⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The galaxy NGC 1427A, found in the Fornax Cluster, looks nothing like a neat spiral or smooth oval—it's shaped like a cosmic boomerang. This odd appearance is the result of NGC 1427A plunging through the dense cluster, which causes its stars and gas to be pulled and stretched, creating a lopsided, arrowhead-like structure as it slowly gets torn apart by gravity. ✨
#galaxies⚡#shapes⚡#mystery⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Not all galaxies fit the classic spiral or oval shapes—take the galaxy LEDA 074886, located about 70 million light-years away, which stunned astronomers with its rare rectangular structure. Unlike the familiar swirls or smooth ellipses, LEDA 074886’s boxy outline is thought to be the result of a merger between two smaller galaxies, sculpting a cosmic shape almost never seen in the universe. ✨
#galaxies⚡#mergers⚡#shapes⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The galaxy ESO 137-001, streaking through the Norma Cluster about 220 million light-years away, has a spectacular "tadpole" shape with long blue tails streaming out behind it. These tails are made of hot, stripped gas and young stars that formed as the galaxy plunges through the dense cluster, showing how powerful cosmic forces can stretch and reshape galaxies far beyond the classic spirals and ovals. ✨
#galaxies⚡#shapes⚡#cluster⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The galaxy known as the Tadpole Galaxy (UGC 10214), about 420 million light-years away in the constellation Draco, is famous for its long, sweeping tail that stretches over 280,000 light-years. This striking "tadpole" shape was created when another galaxy passed close by, pulling out a stream of stars, gas, and dust—a cosmic encounter that gave the Tadpole Galaxy its unforgettable, bizarre silhouette among the galaxies. ✨
#galaxies⚡#shapes⚡#collision⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels