Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
विकास पथ को गति दे रहे भारत के राष्ट्रीय राजमार्ग।। 🛣️
भारत के सड़क नेटवर्क के विस्तार के साथ-साथ प्रगति की यात्रा का गवाह बनें। यह परिवर्तन वास्तव में #NewIndia की गति और विकास का प्रमाण है।
#InfrastructureDevelopment
#Highway
Experience high-speed connectivity for industrial centres with the Nashik Phata – Khed Corridor!
Enhancing travel between Pune and Nashik along NH-60, this corridor reduces congestion around Pimpri-Chinchwad, fostering industrial growth and smoother transportation.
#InfrastructureDevelopment#NewIndia
#TransformingIndia
Guwahati's connectivity gets a major boost with the new Northern Guwahati Bypass!
Upgrading the existing bypass and constructing a major bridge over the Brahmaputra, this project will significantly improve travel efficiency and support regional development.
#InfrastructureDevelopment#NewIndia
#TransformingIndia
The Kanpur Ring Road project will complete the 6-lane National Highway Ring around Kanpur!
Enhancing traffic flow and reducing congestion, this project is set to transform Kanpur’s connectivity, making travel within the city and to other regions smoother and faster.
#InfrastructureDevelopment#NewIndia
#TransformingIndia
Boost industrial connectivity with the Pathalgaon & Gumla sections of the Raipur-Ranchi National High-Speed Corridor!
Linking mining areas in Gumla, Lohardaga, Raigarh, Korba, and Dhanbad to industrial zones in Raipur, Durg, Bilaspur, and Bokaro, this project promotes faster, efficient transportation.
#InfrastructureDevelopment#NewIndia
#TransformingIndia
Pilgrims can now reach Ram Mandir via the Ayodhya Ring Road!
This project facilitates quicker movement for devotees visiting the sacred site, enhancing the spiritual journey and supporting regional tourism and infrastructure development.
#InfrastructureDevelopment#NewIndia
#TransformingIndia
Ensure smooth freight movement with the Tharad – Deesa – Mehsana – Ahmedabad National High-Speed Corridor!
This corridor links industrial regions in Punjab, Haryana, and Rajasthan to major ports in Maharashtra, enhancing logistics efficiency and boosting industrial growth.
#InfrastructureDevelopment#NewIndia
#TransformingIndia
Unlock the North East with the Kharagpur-Moregram National High-Speed Corridor!
Connecting West Bengal, Odisha, and Andhra Pradesh to the North-East, this project will increase traffic capacity by over 5 times, promoting regional development and improving travel efficiency across these states.
#InfrastructureDevelopment#NewIndia
#TransformingIndia
Travel faster to iconic landmarks with the Agra-Gwalior National High-Speed Corridor!
Enhancing connectivity to tourist hotspots like Taj Mahal, Agra Fort, and Gwalior Fort, this corridor will double traffic capacity and cut travel time by 50%.
#InfrastructureDevelopment#NewIndia
#TransformingIndia
Experience seamless travel with 8 national high-speed road corridors spanning 936 km!
With an investment of Rs 50,655 crore, these corridors are set to revolutionize connectivity and boost economic growth across India.
#InfrastructureDevelopment#NewIndia
#TransformingIndia
India's National Highways - From Roadblocks To Road Wonders!
Witness the wide ride of progress as India's road network expands, solidifying its position as one of the largest in the world. This transformation is truly a testament to #NewIndia's growth and development.
#InfrastructureDevelopment
#Highway