Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🪐 Discovered in 2013, asteroid 2013 TX68 drew attention due to its unpredictable orbit, which allowed it to pass within a few million kilometers of Earth—close enough that its next flyby in 2046 will be closely watched. This space rock is roughly 30 meters wide, similar in size to the Chelyabinsk meteor, and while it's not currently on a collision course, its uncertain path highlights the challenges of tracking smaller, potentially hazardous asteroids. ✨
#asteroids⚡#nearearth⚡#planetarydefense⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Asteroid (4660) Nereus is a near-Earth object about 330 meters wide, famous for its frequent close approaches to our planet due to its elongated orbit around the Sun. While it poses no immediate danger, Nereus occasionally comes within just a few million kilometers of Earth, making it one of the more closely watched space rocks for future planetary defense planning. ✨
#asteroids⚡#nearearth⚡#planetarydefense⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Asteroid (29075) 1950 DA is one of the most closely monitored potentially hazardous asteroids, as it has a slim chance of impacting Earth in the year 2880. This kilometer-sized space rock spins so fast—completing a rotation every 2.1 hours—that its own gravity barely holds it together, making it a real cosmic oddity among dangerous near-Earth objects. ✨
#asteroids⚡#planetarydefense⚡#spacehazards⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The asteroid (410777) 2009 FD is a near-Earth object roughly 472 meters wide, with an orbit that brings it uncomfortably close to our planet every few decades. Although calculations show it poses no immediate threat, its path is closely watched because even moderate-sized objects like 2009 FD can cause widespread devastation if they ever collide with Earth. ✨
#asteroids⚡#planetarydefense⚡#nearearthobjects⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 In 2013, astronomers tracked asteroid (367943) Duende, a 30-meter-wide space rock that passed just 27,700 kilometers above Earth's surface—closer than many weather satellites. Duende’s near miss was remarkable not only for its proximity, but because it approached from the Sun’s direction, making it hard to spot in advance and highlighting the ongoing challenge of detecting small but potentially hazardous asteroids before they pass close to our planet. ✨
#asteroids⚡#duende⚡#planetarydefense⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The asteroid (2011) AG5, classified as a near-Earth object, made headlines because it once had the highest estimated probability of impacting Earth in the 21st century. Thanks to ongoing observations, scientists have refined its path, showing it will safely pass by our planet in 2040, but its close approach—just 1.1 million kilometers away—demonstrates how carefully even modest-sized asteroids must be tracked to protect Earth from unexpected cosmic threats. ✨
#asteroids⚡#nearearthspace⚡#planetarydefense⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries