Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
Weekend
Let's begin,
Feet on feet
Following each other
Across the room,
Like a fleet
Unrequited and washed up
At shores
Unreachable and silent dead
Now pace up,
Reach my hand
Sigh
And burn
With violent fumes,
Find me a blink away
In carpeted elevators
Locked
In gaze
Finally,
Race me to the longest yard
At 3
Past midnight,
Rest on this hammock
Of tacit fears
And inhibitions,
Ask me
If I know myself,
I'll pause
And say
More each day
When I'm with you.
#review#poetry#ap
I've been thinking of life
And it was raining season
Life is worse than the hell
Why? Couldn't get reason
How and when will i get rid
From this unbearable pain
People can shouting loudly
I could not cry in the rain
#ap#review#shortpoem
Tanka : 57577
I'm alone at my place
Perhaps, someone will come here
A beautiful lady, and
Will take my hand in her hand
Maybe will say I'm with you.
#ap#review#tanka
Tanka : 57577
If I do any crime!
If I hurt you more before:
Will you forgive me?
Like you forgave me before;
I like you because of these.
#ap#tanka#review
I sniffed our wilted pink roses
When thy old letters, I dupp'd
Haue not rights to touch thou
To hug, To kiss thou forehead
#Ap#quatrain#review
Words : Old/Middle into Morden English
Thy - your
dupp'd -opened
Haue/Hast not - have not
Thou - you (subject)
• Quatrain •
The world can't see inside's pain
And, tears are hidden in the rain
Even if the world calls me stupid
But, Her voice affects like music
#ap#quatrain#review
#NATO
Jens #Stoltenberg (#Ap|S&D): “Onorato dalla decisione degli Stati NATO di estendere il mio mandato come Segretario Generale fino al 1° ottobre 2024. Il legame transatlantico tra Europa e Nord America ha garantito la nostra libertà e sicurezza per quasi 75 anni e, in un mondo più pericoloso, la nostra Alleanza è più importante che mai.”
@OsservatorioEsteri