+ 5
Can we write a statement after return statement?
Will the statement will execute?
6 Answers
+ 5
Everything you put after a valid return statement will effectively be treated as a comment. Try it and write whatever in a line after. It doesn't even have to be a valid Python syntax...
def k():
return 0
Yougottabekiddingme!!!
print(k())
>>>
0
+ 3
You can in this way.
def func(a):
if a > 5:
return
print("abc")
#if a > 5 abc won't be printed.
+ 3
You can! Use try finally code block.
Eg.
def myFunc():
try:
print('hello')
return
print('python')
finally:
print('world')
This will print 'hello world' . Because 'finally' guarantee that it will execute last no matter what (even in case of exeception). Hope it helps :)
+ 1
You can write a statement after a return statement BUT it will NOT be executed.
0
No ! The statement will not execute, because all statement you write after return statement is considered like a comment.
0
it won't execute