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

Резултати

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

Пребарај: #piyush

当前筛选 #piyush清除筛选
Pensive|

@PensivePost · Post #5015 · 23.03.2021 г., 10:41

When I was old I'd never chase peace, Now I can't live without this. When I was old I never thought I'll miss, Now everything is temporary still I seek. Used to cry when someone leaves me alone, Now me, myself and I love to stay at home. Used to cry when someone shows me the ghost, Now I don't know how to cry every day I see the living ghost in the people. I always live with the right people, who might care! If anybody wants to prove me wrong, I say “I think you are right there”. Don't let the world falls you down, you're doin alright, damn! #review#piyush

Pensive|

@PensivePost · Post #5001 · 15.03.2021 г., 09:59

Baby you can't ruin all the beautiful things Stop doing all these suitable mood swings Why did you think, That way. Sometime mind fucked up And the heart has to pay. I don't want to hate you Please don't make me to say it. We should forget bout us And shall pretend like we don't remember each other name. You were behind the fame and I understand. I was in pain but You didn't understand. #piyush#review

Pensive|

@PensivePost · Post #5013 · 22.03.2021 г., 10:27

Your world what was so busy So I left alone and that wasn't easy Our love didn't leave any meaning Then I called you and you keep it on ringing Now my heart can't stop singing My mind can't stop thinking 'Bout you I thought my friend would leave me, but not you I hope you too wanted the same thing Love, lust and fam thing Our future is now too far Am I blind? Why don't I can't see? Can't see, can't see, can't see.. ? Anymore.. Don't know 'bout those First, they love and then leave What made you by leaving them broke? #piyush#poetry#review

Pensive|

@PensivePost · Post #4878 · 06.02.2021 г., 14:27

Spectrum of love I had once affected from love We were one, now it's just get separate by move No one tried to prove Now we aren't into.., Love. But still checking up on each other's. Maybe we still don't want to get lose That was best life, when I had choose.., Her. Now it's getting worse and I can't do.., Anything. Stucked up on penny things, You and me had fucked up everything. Me and her, had dreams. It was fucked up ever since. #review#piyush#verse

Pensive|

@PensivePost · Post #4872 · 04.02.2021 г., 18:06

Why it's feels so alone? Maybe cause of I didn't hear my fav songs It's night and it's so dark It's feeling like I'm lost When this night will end? Stop living in my head! What if I stay calm? And what if you stay with me? There are thousands of words to say And you are not here to listen to me One day you would come at any reason for me And one day I'll be gone for many reasons and you won't see that coming.. #review#piyush#verse

Pensive|

@PensivePost · Post #4862 · 03.02.2021 г., 11:11

She just want to be alright, Even things are not all right, She's now crying like all night, She chooses darkness so she lose light. Now even god wants to know, who's right ? I didn't do anything wrong and idk if I have did maybe, No one knows how much I need you my baby, Again! You left me but when will this pain? You got yourself outta my life and I'm still in that lane. Sometime true love dies and no one gives a damn, Tell me after broking me what did you gain? #review#piyush#verse

Pensive|

@PensivePost · Post #4856 · 02.02.2021 г., 17:17

She cried and said “why you want to control me?” I cried and said “it doesn't make me lonely.” She said is love isn't there to make we us? I said that's right but what bout lust? She still think that I was hiding something And than she left me saying you share nothing Now she miss me too Losing controlling too She thought I was fake But now who left true? #verse#review#piyush

Pensive|

@PensivePost · Post #4966 · 27.02.2021 г., 19:37

She was drunk and lonely Alone in the city maybe that's why she don't know me Writing bout her maybe that's made her know me Hooked up with her cause she was horny She didn't said any word but when I left she said wish you'd met me before I just saw in her eyes and felt like she want more Her body wanting me but she couldn't said any word Maybe she don't want to get addict or maybe she don't want to do this anymore Her weight was much heavy but at that time, I made her feel low She said wanting this so hard, waiting from the months Tell me how you get good at this ? now I can't satisfy at once I just started from removing clothes and slowly her body started gettin burn Pleasure come with pain though but she was having fun Leg was stucked with her pants but it looks like she wanted to run Or maybe she wanted the one who won't run and drive her crazy And later, she found me and I found her, no one is between us (Erotic breathing and saying) 'Amazing'. #review#piyush#fictionalstory

Pensive|

@PensivePost · Post #4855 · 02.02.2021 г., 17:05

She cried and said “why you want to control me?” I cried and said “it doesn't make me lonely.” She said is love isn't there to make we us? I said that's right but what bout lust? She still think that I was hiding something And than she left me saying you share nothing Now she miss me too Losing controlling too She thought I was fake But now who left true? #review#verse#piyush#pease