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

Резултати

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

Пребарај: #remember

当前筛选 #remember清除筛选
Lsposed Modules Updates Tracker

@lsposed_Modules_Updates_Trackers · Post #6229 · 18.03.2026 г., 15:30

#Remember#rafareborn 模块:eu.hxreborn.remembermysort 简介:Remember My Sort 版本:300-3.0.0 更新时间:2026/03/18 18:13:22 更新日志: 💥 BREAKING CHANGES due to df21727 - migrate to libxposed API 101 (commit by @hxreborn): Migrates from libxposed API 100 to 101. API 100 will no longer be supported once 101 is officially released. An LSPosed Manager with API 101 support may not be @lsposed_Modules_Updates_Trackers | @lsposed_Geeks_Bot

Lsposed Modules Updates Tracker

@lsposed_Modules_Updates_Trackers · Post #6153 · 09.03.2026 г., 21:30

#Remember#rafareborn 模块:eu.hxreborn.remembermysort 简介:Remember My Sort 版本:202-2.0.1 更新时间:2026/03/10 04:51:04 更新日志: 🐛 Bug Fixes ef31320 - prevent dimId from being misinterpreted as the sort direction (commit by @hxreborn) Restores sort preferences for users upgrading from v1.x. @lsposed_Modules_Updates_Trackers | @lsposed_Geeks_Bot

Journey to Fluency

@fluencyinenglish · Post #7068 · 23.04.2019 г., 03:06

‍#grammar #remember #infinitive 1⃣ Remember + Infinitive 1⃣ به خاطر داشتن کاری که باید در اینده انجام دهید 2⃣ Remember + Gerund 2⃣ به خاطر داشتن کاری که در گذشته انجام داده‌اید 🆘 Infinitive: to + Verb 🆘 Gerund: Verb + ing @ieltsstrategies @fluencyinenglish

Journey to Fluency

@fluencyinenglish · Post #6746 · 08.01.2019 г., 06:20

#remember #forget #try @fluencyinenglish ❇️Remember + gerund This is when you remember something that has happened in the past. You have a memory of it, like being able to see a movie of it in your head. I remember going to the beach when I was a child. (= I have a memory of going to the beach). He remembers closing the door. (= He has a memory of closing the door). @fluencyinenglish ❇️Remember + to + infinitive This is when you think of something that you need to do. (And usually, you then do the thing). I remembered to buy milk. (= I was walking home and the idea that I needed milk came into my head, so I bought some). She remembered to send a card to her grandmother @fluencyinenglish ❇️ Forget + gerund This is the opposite of remember + gerund. It's when you forget about a memory, something that you've done in the past. Have we really studied this topic before? I forget reading about it. I told my brother that we'd spent Christmas at Granny's house in 1985, but he'd forgotten going there. @fluencyinenglish ❇️Forget + to + infinitive This is the opposite of remember + to + infinitive. It's when you want to do something, but you forget about it. I forgot to call my mother. (= I wanted to call my mother, but when it was a good time to call her, I forgot. I was thinking about something else, and the idea to call my mother didn't come into my head). She keeps forgetting to bring his book back. @fluencyinenglish ❇️Try + gerund This is when you do something as an experiment. The thing you do is not difficult, but you want to see if doing it will have the result that you want. I wanted to stop smoking, so I tried using nicotine patches. (= Using nicotine patches was easy, but I wanted to know if it would help me stop smoking). She tried giving up chocolate, but it didn't help her lose weight. (It was easy for her to give up chocolate. She gave it up to see if it would help her lose weight, but it didn't). @fluencyinenglish ❇️Try + to + infinitive This is when the thing you do itself is difficult. In the present tense or future tense, this means you might not succeed in doing it. In the past tense, it means that you made an effort to do the thing, but you did not succeed. I'll try to carry the suitcase, but it looks too heavy for me. She tried to catch the bus, but she couldn't run fast enough @fluencyinenglish ❇️Regret + gerund This is when you are sorry about something you did in the past and you wish you hadn't done it. I regret going to bed so late. I'm really tired today. She regrets leaving school when she was sixteen. She wishes that she had studied more and then gone to university. @fluencyinenglish ❇️Regret + to + infinitive We use this construction when we are giving someone bad news, in quite a formal way. The verb is almost always something like 'say' or 'tell' or 'inform'. I regret to tell you that the train has been delayed. The company regrets to inform employees that the London office will close next year. @fluencyinenglish

12
ПретходнаСтраница 1 од 2Следна