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

Резултати

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

Пребарај: #infra

当前筛选 #infra清除筛选
Indian Development News 🇮🇳

@developmentnewsindia · Post #44438 · 05.05.2026 г., 08:00

Change in West Bengal Govt also means projects stuck now can be implemented 🔸Varanasi - Kolkata Expressway 🔸Gorakhpur - Siliguri Expressway 🔸Extension of Eastern Dedicated Freight Corridor from Bihar to Bengal 🔸Varanasi - Siliguri High Speed Rail Corridor will also see timely execution #Infra

Hashtags

Indian Development News 🇮🇳

@developmentnewsindia · Post #44272 · 01.05.2026 г., 04:32

India's toll plazas gets a serious upgrade. The Multi-Lane Free Flow (MLFF) system is now live and aim is to eventually transition to no boom barriers, no queues, no stopping with FASTag deducted automatically. 108 toll plazas across major national highways, with full rollout targeting all four-lane+ corridors by 2029. The end goal is to eliminate human intervention, no revenue leakage, no fuel wasted idling at barriers. #Infra

Hashtags

Indian Development News 🇮🇳

@developmentnewsindia · Post #44066 · 25.04.2026 г., 14:38

Mumbai-Ahmedabad Bullet Train Project: Assembly of India's largest-ever Tunnel Boring Machine (TBM), with a diameter of 13.56 meters, progressing at Shaft 2 in Vikhroli, Mumbai. Drilling is expected to begin in July 2026. #Infra

Hashtags

Indian Development News 🇮🇳

@developmentnewsindia · Post #43982 · 23.04.2026 г., 12:33

PM Modi to inaugurate the 594 km long Ganga Expressway on April 29 India's longest expressway, linking Meerut-Prayagraj via 12 districts, cutting travel time by ~50% and boosting connectivity & trade #Infra

Hashtags

Indian Development News 🇮🇳

@developmentnewsindia · Post #43860 · 20.04.2026 г., 12:46

Not just sea bridges, coastal roads, tunnels, and metros. In housing too, Mumbai is being rebuilt from the ground up. Dharavi: 641 acres, ₹95,700 crore. Motilal Nagar in Goregaon: 143 acres, up to ₹1,00,000 crore. BDD Chawls in Worli: 87 acres with Tata, Capacit'e and CITIC group. Bhendi Bazaar Kamathipura 5 landmark redevelopment projects with Adani, Tata, and marquee developers. Combined investment crossing ₹2,00,000 crore. The city that powers India's economy is finally getting the urban infrastructure its ambition always deserved #Infra

Hashtags

Indian Development News 🇮🇳

@developmentnewsindia · Post #43653 · 16.04.2026 г., 03:04

Zoji La Tunnel Nears a Major Breakthrough India’s strategic Zoji La tunnel connecting Kashmir to Ladakh is on the brink of a breakthrough, with the final blast expected by end of May 2026. Only 300 meters remain of the 13.1 km tunnel, with work progressing from both Sonamarg and Minamarg ends. #Infra

Hashtags

Indian Development News 🇮🇳

@developmentnewsindia · Post #43620 · 15.04.2026 г., 08:20

Infrastructure spending in India has grown six-fold to more than ₹12 lakh crore a year since 2014, compared with less than ₹2 lakh crore before 2014, Prime Minister Narendra Modi said on Tuesday. #Infra

Hashtags

Indian Development News 🇮🇳

@developmentnewsindia · Post #43256 · 05.04.2026 г., 12:44

Bogibeel Bridge (4.94 km) built on the mighty Brahmaputra river cuts Dibrugarh–Itanagar road distance by 150 km and rail by 705 km. Project cost revised to ₹4,857 crore from ₹3,230 crore; inaugurated in 2018 after 2002 start. Double-line rail + 3-lane road link boosts connectivity across Assam–Arunachal. #Infra

Hashtags

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