class Solution(object): def addDigits(self, num): return (num % 9 or 9) if num else 0
@v7v587 If it would be about code golfing, I will prefer your solution. But in current situation I tried to be more explicit.
@viakondratiuk Oh yes, you are right. And I just want to get familiar with this grammar, because I just begin to learn python.
I feel happy to know the use of "and","or" like this from your code. Thanks!
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.