RE: Python practice tests

You are viewing a single comment's thread from:

Python practice tests

in coding •  6 years ago 

return is a construction used in the code block of a function definition + after the return instruction is inserted the code block will stop executing anything so :

def print_nums(x):
for i in range(x):
print(i)
return
print_nums(10)

Program takes 0, verifies that is in range of 10 and prints 0
Because of the return statement program stops executing the code

If return is deleted from code the output will be
0
1
2
3
4
5
6
7
8
9

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

That depends on the indentation:-)

The indentation went wrong because of improper markdown