def cumulative_sum(n):
= 0
total for i in range(1,n+1):
+= i
total return total
print("Cumulative sum from 1 to 4 is", cumulative_sum(4))
Cumulative sum from 1 to 4 is 10
return
statementreturn
statementdef cumulative_sum(n):
total = 0
for i in range(1,n+1):
total += i
return total
print("Cumulative sum from 1 to 4 is", cumulative_sum(4))
Cumulative sum from 1 to 4 is 10
cumulative_sum(4)
will evaluate to the integer number 10
.
int
.cumulative_sum(cumulative_sum(4))
return
always exits the function!return
?return
is the null object, which in Python is called None
. For example: