If I want to find the sum of a number s numbers such as

0 votes
  • Input: 932
  • Output: 14, which is (9 + 3 + 2)

    What is the fastest way of doing this?

    I instinctively did:

    sum(int(digit) for digit in str(number))
    

    and I found this online:

    sum(map(int, str(number)))

Sep 11, 2023 in Python by Satyawrat
• 460 points

edited 5 days ago 10 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP