TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #83 · 11 мај

У строки в Python есть два очень похожих метода. На столько похожих что кажется они делают одно и тоже. Это метод isdigit() и isnumeric() Давайте посмотрим зачем нам два одинаковых метода? И так ли они одинаковы? Очевидно что isdigit() говорит нам, состоит ли строка только из чисел 0-9 >>> '12'.isdigit() True >>> '12x'.isdigit() False >>> '-12'.isdigit() False >>> '12.5'.isdigit() False Можно предположить что isnumeric() делает более глубокий анализ и распознаёт в строке float или отрицательное число. >>> '15'.isnumeric() True >>> '-15'.isnumeric() False >>> '15.2'.isnumeric() False Нет, всё так же как и с другим методом. В чем же тогда разница? Для начала посмотрим следующие примеры: >>> '5'.isdigit(), '5'.isnumeric() # Обычная цифра 5 # True, True >>> '꧕'.isdigit(), '꧕'.isnumeric() # Яванская 5 # True, True >>> '෩'.isdigit(), '෩'.isnumeric() # Синхала 3 # True, True >>> '৩'.isdigit(), '৩'.isnumeric() # Бенгальская 3 # True, True >>> '༣'.isdigit(), '༣'.isnumeric() # Тибетская 3 # True, True >>> '³'.isdigit(), '³'.isnumeric() # 3 верхний индекс (степень) # True, True >>> '𝟝'.isdigit(), '𝟝'.isnumeric() # Математическая двойная 5 # True, True >>> '๔'.isdigit(), '๔'.isnumeric() # Тайская 4 # True, True >>> '➑'.isdigit(), '➑'.isnumeric() # 8 в круге # True, True А теперь примеры в которых, по мнению Python, результаты не равны >>> '¾'.isdigit(), '¾'.isnumeric() # дробь три четверти # False, True >>> '⅕'.isdigit(), '⅕'.isnumeric() # дробь одна пятая # False, True >>> '𒐶'.isdigit(), '𒐶'.isnumeric() # клинопись 3 # False, True >>> '三'.isdigit(), '三'.isnumeric() # 3 из унифицированной идеограммы # False, True >>> '⑩'.isdigit(), '⑩'.isnumeric() # цифра 10 в круге # False, True >>> 'Ⅳ'.isdigit(), 'Ⅳ'.isnumeric() # Римская 4 # False, True >>> '𑇪'.isdigit(), '𑇪'.isnumeric() # Сенегальская архаическая 10 # False, True >>> '𐌢'.isdigit(), '𐌢'.isnumeric() # Этрусская цифра 10 # False, True >>> 'ↂ'.isdigit(), 'ↂ'.isnumeric() # Римская цифра 10000 # False, True >>> '〇'.isdigit(), '〇'.isnumeric() # Символ ККЯ ноль # False, True Получается, что isdigit() говорит нам, является ли символ десятичной цифрой или спецсимволом, имеющим цифирное значение после преобразования. В свою очередь isnumeric() включает все дополнительные символы юникода которые имеют отношения к числовым и цифровым представлениям. Ну и пара примеров в которых в обоих случаях символ не является числом, это эмодзи. >>> '🕙'.isdigit(), '🕙'.isnumeric() # эмодзи 10 часов # False, False >>> '7️⃣'.isdigit(), '7️⃣'.isnumeric() # эмодзи 7 # False, False Также есть еще один дополнительный и весьма полезный метод isdecimal(). Он нам сообщает, можно ли из указанного символа сделать простую десятичную цифру. То есть сработает ли метод int(x) >>> '෩'.isdecimal(), int('෩') # Синхала 3 # True, 3 >>> '➑'.isdecimal(), int('➑') # 8 в круге # False, ValueError Какие выводы? 🔸 При определении цифры в строке isdigit() подходит лучше чем isnumeric(), но оба не гарантируют успешную конвертацию в int 🔸 Для однозначного определения возможности преобразования строки в int лучше подходит метод isdecimal() 🔸 Для однозначного определения символов 0...9 лучше использовать regex Полный список символов юникода которые определяются как numeric #basic

Hashtags

Резултати

Пронајдени 7 слични објави

Пребарај: #hkpolice

当前筛选 #hkpolice清除筛选
香港人的蘋果

@Appledailyhk26 · Post #55660 · 10.10.2023 г., 00:38

#英文#港聞 Oct 4: Yung Wai-yip was subdued for holding white flowers. People nearby question the necessity of the force used by the #HKPolice. Credit: boomheadhk 🍎保留一點真相、一些堅持: https://t.me/appledailyhk26 🍎蘋果報料熱線: @Appledailyhk_bot 🍎蘋民不蘋則鳴!2.0 https://t.me/hkerappledaily2

香港人的蘋果

@Appledailyhk26 · Post #56536 · 12.11.2023 г., 22:50

#英文#港聞 More info about #721YuenLongTerrorAttack from the book "Among the Braves". It says that there were 5 different triad groups involved in the attack. They had a WhatsApp group which the #HKPolice had access to. "A week prior, members of five separate triad groups joined a WhatsApp group to discuss plans to “defend their homeland,” Yuen Long. It was rare for these groups to come together, as they often clashed over their share of illicit business. As the triad groups coordinated their plans for July 21, a detective sergeant from the anti-triad bureau that oversaw the area was reading along. He had managed to gain access to the group chat, giving him unfettered insight into the plans." The article also reported that Stephen Ng, political assistance to the mainland affairs mentioned about "wear white only" dress code. "The political assistant to the secretary for mainland affairs had invited some others to join him at the banquet. He gave them a very specific dress code: Wear only white.”

Hong Kong Democracy Movement

@hkdmovement · Post #7841 · 23.09.2024 г., 03:13

5 years ago today, Chan Yin Lam passed away mysteriously. During 2019, many HongKongers went missing or died. Several times #HKPolice were caught throwing bags with the size of a human into the sea. Her body was found in the sea, naked, yet people knew her claimed that she was a diver. #HKProtest#neverforgiveneverforget #FreeHK

香港人的蘋果

@Appledailyhk26 · Post #56534 · 12.11.2023 г., 22:34

#英文#港聞 #721 After 4 years, more information about #721YuenLongTerrorAttack has been revealed as the trial against Lam Cheuk-ting, a former democratic lawmaker who claimed to be there to understand the situation. Witness B, who was a staff at the station time, said that police contacted the station through whatsapp to send 2 police to monitor the station on July 19th, 2 days before the attack. On 20th, police arranged to have 2 police to standby at the monitor room starting at 5:00PM on 21st. There were 2 police in the monitor room during the attack on 21st. Clearly, #HKPolice knew that the local thugs had planned the attack 2 days before the incident. 🍎保留一點真相、一些堅持: https://t.me/appledailyhk26 🍎蘋果報料熱線: @Appledailyhk_bot 🍎蘋民不蘋則鳴!2.0 https://t.me/hkerappledaily2

Hong Kong Democracy Movement

@hkdmovement · Post #7276 · 11.03.2024 г., 11:18

#HongKongers express fear as govt considers expanding #HKPolice power under proposed #Article23 security law. Extended detention period without charge and restrictions on legal representation raise concerns about #individualrights and freedoms. https://hongkongfp.com/2024/03/07/hong-kong-considers-extending-detention-period-of-arrestees-to-up-to-14-days-in-national-security-cases/ #HongKong#PolicePower

香港人的蘋果

@Appledailyhk26 · Post #56081 · 24.10.2023 г., 13:04

#英文#港聞 Oct 17: A student held piece of paper writing "721唔見人" at a college recruitment event which #HKPolice participated. It refers to the day no police showed up when thugs attacked citizens indiscriminately on July 21, 2019. The school security told him to leave soon after. #721YuenLongTerrorAttack #721YuenLongAttack #HKPoliceTerrorist 🍎保留一點真相、一些堅持: https://t.me/appledailyhk26 🍎蘋果報料熱線: @Appledailyhk_bot 🍎蘋民不蘋則鳴!2.0 https://t.me/hkerappledaily2

Hong Kong Democracy Movement

@hkdmovement · Post #7500 · 15.06.2024 г., 17:17

Jun 15: Leung Ling-kit wore a yellow raincoat with an umbrella standing at Pacific Place Patio at 4:30. He wrote “Carrie Lam kills Hong Kong” & “Black Cops are cold blooded” on a banner and hang it at the building for everyone to see. Police and negotiators went but did not allow anyone to go near him. At 9:15pm, he jumped down. That was the beginning of the 2 million+1 people march the next day. People still commemorate him in Hong Kong to this day while countless of #HKPolice was standing by as if having a flower in hand can damage #nationalsecurity. This is the excuse they use to arrest people anyway. The laws that we having been fighting against, the extradition bill, national security law & article 23 are laws that criminalize thoughts. #leunglingkit#HongKongProtest#5demandnot1less#fightforfreedom#standwithhongkong