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

Резултати

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

Пребарај: #guasia

当前筛选 #guasia清除筛选
Gumart Announcement 🛒

@gumartec · Post #241 · 14.04.2025 г., 00:11

🌊 GuAsia Winner Has Arrived at Songkran. Congratulation winners!🇹🇭 From the leaderboard to the land of water fights and tradition, our GuAsia winners have officially landed in Bangkok to experience the legendary Songkran Water Festival - live and in person! 🛫💧 A round-trip ticket to Bangkok from April 13 to April 15 to experience one of the most iconic cultural events on Earth has already been sent straight to the winner’s wallet, along with a personal notification. ✈️ 🏆 As part of Gumart’s biggest campaign ever, Gu Go Global, this was Asia’s turn to shine—and the energy was real. 🏁With more giveaways coming to every continent, your chance might be just around the corner! #GuGoGlobal#GuAsia

Gumart Announcement 🛒

@gumartec · Post #382 · 25.01.2026 г., 10:14

⏱ 2 DAYS LEFT — Don’t Miss This! 🚨 💥 The clock is ticking. Only 48 hours remain before our GuAsia Mini-Game officially closes. ❗️ What’s at stake? Top 5 players on the leaderboard will secure exclusive rewards, including real-world travel experiences, not just digital prizes. 🌍 This isn’t just a game. It’s your chance to turn activity into real movement, rewards into real journeys, and rankings into real recognition. 👀 🔥 Final push starts NOW: 1️⃣ Invite more friends 2️⃣Climb the leaderboard 3️⃣Lock in your spot ⏰ 2 days left. Once it’s over — it’s over. #GuGoGlobal#GuAsia#FinalCountdown

Gumart Announcement 🛒

@gumartec · Post #246 · 19.04.2025 г., 03:46

🌊 Gumart in Songkran – Thailand 🇹🇭 🌐#GuGoGlobal Campaign – Taking Web3 to the Heart of Culture! 📍 Checkpoint: Songkran Festival, Bangkok, Thailand One of our GuAsia winners has just shared their unforgettable journey at the legendary Songkran Festival in Bangkok - after receiving their exclusive reward from the #GuGoGlobal giveaway. 😱 From vibrant street parades to joyful water fights, this was more than just a trip - it was a moment where Web3 met real-world celebration, and Gumart became part of the experience.⭐️ 💡 This is what Gu Go Global is all about: bringing crypto utility to real life, through people, places, and culture. 🎉And yes - more giveaways are coming to every continent. Your city might be next. #GuGoGlobal#GuAsia#Songkran

Gumart Announcement 🛒

@gumartec · Post #240 · 10.04.2025 г., 07:39

🎉 GuAsia Activation: Fly to Songkran Festival with Gumart!🇹🇭 As part of Gumart’s biggest-ever global campaign, Gu Go Global (April–May 2025), we’re bringing the celebration to Asia with a special giveaway!📈 ✈️ Prize: Round-trip flight ticket to Bangkok, Thailand, to experience the iconic Songkran Water Festival live! 💧 🗓 Duration: April 8 - April 13 📌 How to join: Top 3 referral leaderboard in Asia will receive special prizes – including a flight to Songkran! Be bold, be global. This is your moment. See you in Asia!🔼 #GuGoGlobal#GuAsia#SongkranFestival