Skip to content

Instantly share code, notes, and snippets.

@ioanzicu
Created July 28, 2022 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioanzicu/8fbd9f1c55f7ac9fabc9a21d829b6ba1 to your computer and use it in GitHub Desktop.
Save ioanzicu/8fbd9f1c55f7ac9fabc9a21d829b6ba1 to your computer and use it in GitHub Desktop.
Get the sum of numbers in a list recursively in Python 3.
def sum_nums(nums):
if not nums:
return 0
return nums[0] + sum_nums(nums[1:])
nums = [1, 2, 3, 4, 5]
print(sum_nums(nums))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment