Skip to content
Advertisement

Tag: digits

I want to distinguish between true digit and a string digit

I want to check a ‘x’ string whether it is a digit or not in advance. ‘1’ is naturally a digit. But and I will use ① what is calld a string number very much. I don’t know the range of string numbers IDE judges as a digit. ‘①’.isdigit() returns True. ‘⑴’.isdigit() returns True. ‘ⅰ’ or ‘Ⅰ’ returns False. ‘㈠’

Sum the digits of a number

If I want to find the sum of the digits of a number, i.e.: Input: 932 Output: 14, which is (9 + 3 + 2) What is the fastest way of doing this? I instinctively did: and I found this online: Which is best to use for speed, and are there any other methods which are even faster? Answer Both

Delete digits in Python (Regex)

I’m trying to delete all digits from a string. However the next code deletes as well digits contained in any word, and obviously I don’t want that. I’ve been trying many regular expressions with no success. Thanks! Result: This must not b deletd, but the number at the end yes Answer Add a space before the d+. Edit: After looking

Advertisement