Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🇷🇺 On June 10, 2023, a state reception on the occasion of the national holiday - #RussiaDay was held at the Russian Embassy in Malta. Among the guests were compatriots, public figures, entrepreneurs, representatives of education, science and culture.
❗️Russian Ambassador to Malta H.E. Andrey Lopukhov addressed the audience with a welcoming speech, emphasizing the importance of this annual event for the consolidation of the Russian community living in Malta. He also noted that Russia is ready to cooperate with those countries that declare their readiness and willingness to cooperate with us.
📷The photo exhibitions "Achievements of Russia" and "Beauty of Russia" were presented to the audience.
🎵The evening was accompanied by live performances of Russian and Maltese musical compositions. The guests were offered dishes of the traditional Russian cuisine.
The reception was held in a warm and friendly atmosphere.
#RussiaDay2023🇷🇺🇷🇺🇷🇺
🇷🇺 On June 15, 2023, the state reception on the occasion of #RussiaDay was held at the Hotel Mulia Senayan in Jakarta. The celebration was attended by esteemed representatives of the Indonesian government, socio-political, business, academic, creative and religious circles, compatriots, journalists, as well as foreign diplomats.
🎙️Welcoming remarks at the function were delivered by H.E. Mrs Lyudmila Vorobyeva, Ambassador of the Russian Federation to the Republic of Indonesia (read in full), H.E. Mr Evgeny Zagaynov, Ambassador of the Russian Federation to ASEAN, and H.E. Mr Budi Gunadi Sadikin, Minister of Health of the Republic of Indonesia, as the Guest of Honour.
💬Ambassador Lyudmila Vorobieva: It is a pleasure to welcome you all at the reception on the occasion of the Day of Russia. We are celebrating the unity and the strength of our country which is one of the main players on the global arena and whose people is looking into the future with confidence and pride.
Russia and Indonesia have a long history of successful cooperation traditionally based on principles of friendship, mutual understanding and trustworthy dialogue.
🎵 The cultural programme of the event included works of great Russian composers P.I.Tchaikovsky and S.V.Rachmaninov played by graduates of Russian musical universities, as well as pieces by local dance ensembles and musicians. The Indonesian song "Rayuan Pulau Kelapa" performed in two languages — Russian and Indonesian — took a special place in the programme of the evening.
📸 The Embassy also organised an art exhibition of Russian landscapes which allowed guests to experience the authentic character of our Motherland and to enjoy picturesque views from various parts of Russia.
#RussiaDay
#RussiaDay2023
🇷🇺 On June 12, we celebrate #RussiaDay across the entire country and abroad.
It reflects #Russia’s contemporary development, as well as its centuries-old path, endeavours & achievements.
🇷🇺 Happy Russia Day!
#RussiaDay#RussiaDay2023#Russia1Love#WeAreRussia