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

Резултати

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

Пребарај: #kanaky

当前筛选 #kanaky清除筛选
Egountchi Behanzin Officiel

@egountchibehanzinOfficiel · Post #6327 · 17.05.2024 г., 08:09

Egountchi Behanzin dénonce à la télévision azerbaïdjanaise la colonisation française en Nouvelle-Calédonie, les massacres des autochtones Kanaks et la répression fasciste du gouvernement colonialiste français 🇫🇷 contre les indépendantistes qui réclament le droit à l’autodétermination et l’indépendance de la Kanaky. Vive la résistance du peuple #Kanak ! Liberté pour la #Kanaky ! À bas le colonialisme français ! #NouvelleCalédonie @egountchibehanzin

Egountchi Behanzin Officiel

@egountchibehanzinOfficiel · Post #6332 · 18.05.2024 г., 18:38

L’extrême droite française passe son temps en France à se victimiser avec la théorie du grand remplacement, mais les voilà depuis des jours soutenir la colonisation et le projet du grand remplacement des autochtones Kanaks en Nouvelle-Calédonie du gouvernement colonialiste de France. Quel paradoxe ! #GrandRemplacement#Kanaky#NouvelleCalédonie#Hypocrisie @egountchibehanzinTV

Egountchi Behanzin Officiel

@egountchibehanzinOfficiel · Post #6322 · 15.05.2024 г., 20:29

Vive la résistance du peuple kanak ! Liberté pour la Kanaky ! Le gouvernement colonial fasciste veut interdire TikTok en Nouvelle-Calédonie pour censurer la résistance des Kanak contre la colonisation française. La France, se voulant moralisatrice, cherche à dissimuler au monde entier qu'elle occupe des terres et opprime des peuples en 2024, tout en condamnant la Russie pour une prétendue occupation de l'Ukraine et en envoyant des armes à des groupes néo-nazis. Macron, Darmanin et leur petit chéri Gabriel Attal peuvent bien tenter d'interdire les réseaux sociaux, mais cela n'empêchera pas la Nouvelle-Calédonie de se libérer de l'occupant français. La France coloniale doit restituer les terres spoliées aux autochtones. Les Kanaks ne font que défendre leur terre contre les occupants. #Kanaky#Résistance#Colonialisme#Liberté @egountchibehanzinTV

Egountchi Behanzin Officiel

@egountchibehanzinOfficiel · Post #6354 · 23.05.2024 г., 08:34

Egountchi Behanzin critique la visite coloniale du roitelet Macron en Nouvelle-Calédonie. La visite de Macron en Kanaky est une insulte à la mémoire des martyrs kanaks et un mépris envers les populations. C'est une visite du maître dans la plantation en flammes, venue féliciter les forces d’occupation et d’agression qui, depuis 170 ans, exterminent le peuple autochtone kanak et spolient leurs terres. ======================= Egountchi Behanzin criticizes King Macron's colonial visit to New Caledonia. Macron's visit to Kanaky is an insult to the memory of the Kanak martyrs and a contempt for the populations. It is a visit by the master to the burning plantation, who came to congratulate the forces of occupation and aggression that, for 170 years, have been exterminating the Kanak indigenous people and plundering their lands. #NonALaColonisationDeLaFrance#Solidarité#NouvelleCalédonie#Kanaky#Macron Rejoignez-nous sur Telegram: @egountchibehanzinTV Chaîne 2 - @egountchibehanzinOfficiel

Egountchi Behanzin Officiel

@egountchibehanzinOfficiel · Post #6568 · 24.06.2024 г., 07:02

#NouvelleCalédonie Une nouvelle révolte populaire contre l’occupation française 🇫🇷 a débuté en #Kanaky. Suite à la déportation coloniale en métropole de sept leaders indépendantistes sur ordre de #Macron, les forces coloniales sur place sont débordées et ne parviennent plus à dégager les routes ni contenir la colère. Ils prennent la fuite! Une nouvelle Bérézina en vue ? Bizarrement, pas un mot dans les médias. Il y’a une censure des médias mensonges Sur injonction du gouvernement négrier de France. Mais grâce aux réseaux sociaux, la vérité reste accessible. Soutien indéfectible aux #Kanaks. Vous êtes dans vos droits, c’est de la légitime défense contre l’envahisseur, l'occupant. Défendez comme il se doit la terre de vos ancêtres et n’ayez crainte des milices loyalistes armées par l'état français et protégées par le démagogue #MoussaDarmanin avec ses troupes coloniales. Vive Kanaky ! Vive la liberté ! #EB @egountchibehanzinTV