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

Резултати

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

Пребарај: #descarga

当前筛选 #descarga清除筛选
Avizor

@Avizorweb · Post #2899 · 03.10.2021 г., 01:37

¡Ya llegó la hora de El Doble! Primero que todo escucha nuestra entrada distintiva y no olvides comentarnos qué te pareció. 💬 📣 En este episodio conversaremos con dos estudiantes fundadoras de #Avizor, un proyecto de comunicación que apuesta por visibilizar tabúes, problemáticas sociales y de género. 🗣 El Anteproyecto del Código de las Familias y sus temas más sensibles también entrarán a debate. Sin más, ¡disfruta tu ración! 😉 ⬇️ (#Descarga gratis desde esta nube con la contraseña ElDoble3)

BotsGram®

@botsgram_cu · Post #3105 · 02.11.2020 г., 18:52

¿Que puede hacer este bot? @ytsongdl_bot Descarga música enviando el nombre o el enlace de una canción Idioma: inglés (Visto en @botsgram_cu) #música#descarga

BotsGram®

@botsgram_cu · Post #3090 · 27.10.2020 г., 02:40

¿Que puede hacer este bot? @freemusicprobot El bot encontrará música por su solicitud, por el nombre de la canción o artista. También funciona inline. Idiomas: inglés, ruso (Visto en @botsgram_cu) #música#descarga

BotsGram®

@botsgram_cu · Post #3100 · 02.11.2020 г., 04:02

¿Que puede hacer este bot? @WebSnatchBot Este bot le permite descargar videos de alta calidad de más de mil sitios compatibles. ¡Simplemente envíele un enlace de video y observe cómo sucede la magia! Idioma: inglés (Visto en @botsgram_cu) #videos#descarga

BotsGram®

@botsgram_cu · Post #3096 · 02.11.2020 г., 03:48

¿Que puede hacer este bot? @DirectFileLinkBot Este bot genera un enlace de descarga directa de archivos de Telegram. Idiomas: inglés (Visto en @botsgram_cu) #enlaces#descarga

BotsGram®

@botsgram_cu · Post #3029 · 29.09.2020 г., 02:38

¿Que puede hacer este bot? @FileSharerRobot Este bot puede ayudarlo a crear un enlace para compartir archivos de Telegram Idiomas: inglés (Visto en @botsgram_cu) #enlaces#descarga

BotsGram®

@botsgram_cu · Post #2960 · 12.08.2020 г., 01:29

¿Que puede hacer este bot? @Qualyuploadbot Envíe cualquier enlace URL de descarga directa, y el bot subirá a telegram como archivo / video Idiomas: inglés (visto en @botsgram_cu) #enlaces#descarga

BotsGram®

@botsgram_cu · Post #3021 · 24.09.2020 г., 02:26

¿Que puede hacer este bot? @torrentDxBoT Este bot te ayudará a buscar y descargar contenido de torrent Idiomas: inglés (Visto en @botsgram_cu) #torrent#descarga

BotsGram®

@botsgram_cu · Post #3039 · 05.10.2020 г., 11:31

¿Que puede hacer este bot? @TGYouTube_Bot Este bot puede convertir el enlace de Youtube a video / archivo y MP3 con soporte de miniaturas personalizadas Idiomas: inglés (Visto en @botsgram_cu) #descarga#enlaces#youtube

BotsGram®

@botsgram_cu · Post #2897 · 16.07.2020 г., 02:11

¿Que puede hacer este bot? @GetImageUrlBot Este bot cargará una foto en un sitio y le devolverá el enlace listo para enviar desde cualquier lugar Idiomas: italiano (visto en @botsgram_cu) #fotos#enlaces#descarga

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