Summing Digits of an Integer

  • Share this:

Code introduction


Calculate the sum of all digits in an integer.


Technology Stack : Python built-in libraries

Code Type : Function

Code Difficulty :


                
                    
def sum_of_digits(n):
    return sum(int(digit) for digit in str(n))