Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
😌 Нам всем нужно немного позитивного контента и приободриться! В инфографике посчитали, как можно провести освободившиеся часы ⏳ Спойлер: с пользой и удовольствием. Всем, кто любит смотреть и слушать — must see👇
#stayhome и будьте здоровы!
Some good news,
- April 2020 Security patch has been merged into Evo's source.
- PE's Motorola Face Unlock port has also been added and by the looks of it, it will only support arm64 devices. (huge shoutout to @jhenrique09 for doing the unthinkable)
- Several other changes also are included in the latest source update.
Enjoy and #StayHome
With the COVID-19 pandemic and Circuit Breaker period in Singapore, many businesses were affected. Hawkers, like Carmal, took a beating as well. How did he respond to the crisis? Find out more in the latest episode of #StayHome with NEA Podcast series (https://youtu.be/z9VAPfnxRmE) featuring Carmal from Mad Bros SG, as he shares how he keeps his business afloat during this crisis.
It’s hilarious how fast and obediently the “leftists” jump off the old mass media crisis cart and onto the new one without a second thought.
In the last 6 months it’s been Greta! And Climate Emergency! Then they dropped that like a hot potato and jumped straight into the #StayHome Covid-19 pandemic! But quickly forgot about social distancing and the whole virus itself when the anti-white “George Floyd” race riots broke out.
Every time their media mogul masters come up with something slightly more destructive to the west they can play with, the dogs of society quickly lose interest in their old toys.
You may be concerned about your household energy consumption during this #StayHome period, and one way to counter that is making sure all unnecessary power and appliances are turned off!
Pick up more energy-saving habits at bit.ly/SaveElectricitySaveMoney
Have you heard? We are launching our very own podcast series! 🎧
#StayHome🏠 and tune in to learn more about the current COVID-19 situation, and tips and tricks on how to waste less! Here’s the first episode of our podcast series featuring an SG Clean Ambassador: https://youtu.be/br3Mp0Xn64s
🎬https://youtu.be/rh_cHtkIbeY
#StayHome and when you need to buy essential items, don a mask and keep a safe distance. Crowd management measures will also be in place at relatively popular markets that tend to draw crowds - the list of markers is available at www.nea.gov.sg/our-services/hawker-management/announcements
#SGDengueUpdate 119 cases were reported in the week ending 22 May, 25 cases more than in the previous week. As more of us #StayHome, this could mean more blood meals for the day-biting Aedes mosquito. Keep dengue at bay, by regularly practising BLOCK & SAW. https://go.gov.sg/mozzieproof
PM Lee Hsien Loong announced that the Circuit Breaker will be extended for 4 more weeks beyond 4 May, till 1 June. Here are the key messages.
#SGUnited#StayHome#StaySafe