+ 5

Can we write a statement after return statement?

Will the statement will execute?

10th Feb 2018, 1:47 PM
Jatin Upadhyay
Jatin Upadhyay - avatar
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
10th Feb 2018, 8:36 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 3
You can in this way. def func(a): if a > 5: return print("abc") #if a > 5 abc won't be printed.
10th Feb 2018, 3:47 PM
ƒred
ƒred - avatar
+ 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 :)
10th Feb 2018, 4:24 PM
Sylar
+ 1
You can write a statement after a return statement BUT it will NOT be executed.
10th Feb 2018, 2:09 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
No ! The statement will not execute, because all statement you write after return statement is considered like a comment.
8th Mar 2018, 3:11 AM
Tanoh Le Kadiographe
Tanoh Le Kadiographe - avatar
0
it won't execute
8th Mar 2018, 9:59 PM
Ameer
Ameer - avatar