Skip to content

Tag: digits

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 sp…