Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🕊November 7: The Woman Who Said “No” to Apartheid
🇿🇦🗓 November 7 marks the birthday of Helen Suzman (née Gavronsky; 1917–2009) — a South African activist and politician who bravely stood against apartheid.
She was the only member of Parliament to consistently and unequivocally oppose all apartheid legislation.
Suzman played a crucial role in improving prison conditions for members of the banned African National Congress (ANC), including Nelson Mandela, and she used her parliamentary privilege to bypass government censorship and share reports on the worst abuses of apartheid.
She was nominated twice for the Nobel Peace Prize. 🕊
💬Quotes by Helen Suzman:
• “I was the only one who said ‘no’ to apartheid, but that was no reason to keep quiet.”
• “It is not my questions that embarrass South Africa—it is your answers.”
(Addressed to the apartheid government during her time in Parliament.)
• “The test of civilization is the way that it cares for its helpless members.”
📸 Photo: Wikipedia
#SouthAfrica#History#HumanRights#AntiApartheid#Mandela
🎉June 7 marks the birthday of Johnny Clegg (1953–2019), South African musician, anthropologist, and anti-apartheid icon.
🎶 Known as "The White Zulu," he blended Western rock with Zulu rhythms, language, and dance in groundbreaking ways.
🎤 He co-founded the bands Juluka and Savuka, defying apartheid laws by bringing Black and white musicians together on stage.
🎵 One of his most powerful songs, Asimbonanga, was a tribute to Nelson Mandela during his imprisonment.
🔍Fun fact:
Although many of his songs were banned in South Africa, Clegg gained global fame and became a symbol of cultural resistance and unity.
#JohnnyClegg#Music#SouthAfrica#AntiApartheid#Birthday
🇿🇦Steve Biko — the Voice of Black Consciousness
🗓December 18 marks the birth of Steve Biko (Xhosa Steve Biko; full name Stephen Bantu Biko; 1946–1977), a prominent South African anti-apartheid activist and the founder of the Black Consciousness Movement.
Biko was a committed Pan-Africanist and an advocate of African socialism. His ideas encouraged Black South Africans to reclaim their dignity, identity, and self-worth under apartheid ✊🏿
Killed as a result of police brutality, Steve Biko became a political martyr of the anti-apartheid struggle.
✍️ He wrote under the pseudonym Frank Talk — a name that can be understood both as “Frank, speak” and “honest / outspoken talk,” perfectly capturing the spirit of his writing.
🕯Steve Biko remains a lasting symbol of courage, consciousness, and the fight for human dignity.
#SouthAfrica#History#SteveBiko#AntiApartheid#BlackConsciousness#HumanRights
🇿🇦🗓October 27 marks the birthday of Oliver Tambo (1917–1993) — a South African anti-apartheid activist who served for 24 years as President of the African National Congress (ANC).
🌍 He spent 30 years in exile.
✈️ In 2006, Johannesburg International Airport was renamed O. R. Tambo International Airport in his honor.
💬Quotes by Oliver Tambo:
• 🇿🇦 “A country, a movement, a person that does not value its youth and children does not deserve its future.”
• ⚖️ “Injustice anywhere is a threat to justice everywhere.”
• 🤝 “True leaders do not seek power, they seek to empower others.”
• 🚀 “Progress is not an accident; it is the result of concerted effort towards a common goal.”
• 👥 “Differences should not divide us; they should be celebrated as a reflection of our shared humanity.”
• 💖 “The legacy we leave behind is not measured by material wealth, but by the impact we have on the lives of others.”
#History#SouthAfrica#OliverTambo#AntiApartheid#Inspiration#Leadership#Quotes
🇿🇦🎉On July 19, we remember Christopher van Wyk (1957–2014) — a South African poet, novelist, and beloved children’s author.
✊ He is widely known for his powerful poem In Detention, which exposes the suspicious deaths of political prisoners under apartheid.
📚 His writing was more than art — it was protest, memory, and truth-telling in the face of systemic injustice.
🕊 We remember.
#SouthAfrica#Poetry#AntiApartheid#HumanRights#InDetention#ChristopherVanWyk#Literature#History
🇿🇦On July 21, we honor the legacy of Albert John Luthuli (1898–1967) — South African political leader, anti-apartheid activist, and president of the African National Congress (ANC).
🏆 In 1960, Luthuli became the first African recipient of the Nobel Peace Prize for his unwavering commitment to nonviolent resistance against racial oppression in apartheid South Africa.
✊ His moral leadership, courage, and commitment to equality continue to inspire generations.
💬 "I am a man of peace. My country can be free—without violence."
🕊 We remember.
#AlbertLuthuli#SouthAfrica#NobelPeacePrize#HumanRights#AntiApartheid#History#Freedom#ANC