python获取一组数个位数之和

pyschools Topic 2: Question 9  题目:给定一组整数,获取其个位数之和

Write a function getSumOfLastDigits() that takes in a list of positive numbers and returns the sum of all the last digits in the list.

def getSumOfLastDigits(numList): 
    return sum(x % 10 for x in numList)
getSumOfLastDigits([1, 23, 456])
Out[11]: 10
posted @ 2020-08-04 15:30  九命猫幺  阅读(1053)  评论(2编辑  收藏  举报