Sum of Digits Calculator Function

  • Share this:

Code introduction


This function calculates the sum of all digits of an integer.


Technology Stack : Built-in functions str(), int(), sum(), for loop, if statement

Code Type : Function

Code Difficulty :


                
                    
def sum_digits(n):
    return sum(int(digit) for digit in str(n) if digit.isdigit())