Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🪐 In the star system V Hydrae, located about 1,300 light-years away in Hydra, astronomers have observed mysterious, high-speed "bullets" of hot gas being violently ejected from the dying red giant star. These jets blast out at speeds up to 800,000 kilometers per hour and appear at regular intervals, creating bizarre patterns of moving material that are among the strangest cosmic outflows seen in our galaxy. ✨
#phenomena⚡#stars⚡#jets⚡#nasa⚡#galaxy⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 In the heart of the Centaurus galaxy NGC 5128, the supermassive black hole devours gas and dust, releasing twin jets of particles that stretch for over a million light-years into space. These jets, visible in both radio and X-ray light, show how black holes can not only swallow matter but also launch some of the most powerful streams of energy in the universe, shaping entire galaxies far beyond their event horizons—the invisible boundaries from which nothing can return. ✨
#blackholes⚡#galaxies⚡#jets⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🌎 Deep within the constellation Cygnus, the black hole V404 Cygni occasionally unleashes powerful outbursts, ejecting matter at near light-speed in opposing jets. These rare events are so energetic that the black hole briefly outshines its entire host galaxy, offering a fleeting glimpse into the turbulent ballet around stellar remnants. ✨
#blackhole⚡#cygnus⚡#jets
👉subscribe Universe Mysteries
🪐 In the heart of the galaxy IC 310, astronomers have observed a quasar that suddenly switches between a quiet state and violent outbursts, blasting powerful jets of particles close to the speed of light. Quasars are some of the brightest objects in the universe, powered by supermassive black holes devouring matter, and IC 310’s unpredictable behavior shows how even these cosmic engines can rapidly transform, lighting up entire galaxies in moments. ✨
#quasars⚡#jets⚡#galaxies⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The quasar PKS 0637-752, located about 7.8 billion light-years from Earth, shoots out a jet of particles more than 2 million light-years long—much farther than the diameter of our Milky Way. Quasars are the brilliant, active centers of young galaxies powered by material falling into supermassive black holes, and these enormous jets show how energy can be launched across intergalactic space by the universe’s most powerful engines. ✨
#quasars⚡#jets⚡#galaxies⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 At the edge of the galaxy M87, astronomers have tracked knots of matter racing outward in narrow jets from its supermassive black hole at more than 99% the speed of light. These plasma jets are powered by the black hole’s intense gravity and spin, yet how exactly the black hole manages to launch such focused, high-speed streams remains one of astrophysics’ biggest black hole mysteries. ✨
#blackholes⚡#jets⚡#plasma⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 In the center of the galaxy NGC 2392, also known as the "Eskimo Nebula," astronomers have detected fast, energetic jets of gas blasting outwards at speeds of over 200 kilometers per second. These jets, launched by the dying central star, punch through surrounding shells of glowing gas, creating intricate, layered patterns that make this nebula one of the most visually stunning and mysterious cosmic objects observed by the Hubble Space Telescope. ✨
#nebula⚡#jets⚡#emission⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 In the galaxy PKS 2014-55, astronomers have discovered a cosmic oddity known as an "X-shaped radio galaxy." This galaxy's energetic jets of particles, powered by a supermassive black hole, create two pairs of huge lobes that form a striking X pattern, suggesting a sudden flip in the black hole's rotation or direction—one of the rarest shapes found among radio galaxies. ✨
#phenomenon⚡#radiogalaxy⚡#jets⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 In the spiral galaxy NGC 4945, located about 13 million light-years away in the constellation Centaurus, astronomers have measured jets of material shooting out from the galaxy's core at speeds approaching the speed of light—nearly 299,792 kilometers per second. This dazzling velocity, known as "relativistic speed," shows how cosmic engines powered by supermassive black holes can accelerate particles close to nature’s ultimate speed limit, producing jets that blaze across tens of thousands of light-years. ✨
#speedoflight⚡#relativistic⚡#jets⚡#NGC4945⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels