Post

Python Developer
Python Developer@Python_Dv·
🤔🚀 Comment your answers below! 👇
Python Developer tweet media
English
16
9
62
12.3K
Sergei Kotov
Sergei Kotov@kotov_dev·
@Python_Dv B) 2 This is BAD practice in fact › finally's return 2 overrides try's return 1 › finally ALWAYS executes › Returns in finally override everything For beginners: › Use finally for cleanup (close files, etc.) › Never return from finally -- it masks other returns!
English
0
0
13
801
Jay
Jay@learnaiwthme·
@Python_Dv It prints 2. In Python, the finally block always runs, even if try already returned a value. So this happens step by step: try returns 1 But before leaving the function, finally runs finally returns 2 and overrides the previous return So: print(test()) outputs: 2
English
0
0
6
889
IrisTech
IrisTech@IrisTechss·
@Python_Dv Haven't seen "try" and "finally". I've only seen "if, elif, else". See you there soon.
English
0
0
4
318
Jenny
Jenny@JennyTheDev·
@Python_Dv B) 2 finally always runs, even after return. It overwrites the return value. Python's way of saying "I wasn't done yet"
English
0
0
4
328
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@Python_Dv Answer: B) 2 finally always executes and overrides any return in try. So even though try returns 1, the return 2 in finally wins.
English
0
0
1
689
Raza Ali
Raza Ali@stuckhere4ever·
@Python_Dv It prints 2 but if I see this I’m going to go into a corner and cry for a week
English
0
0
0
39
Biel Men
Biel Men@BielMenHaha·
@Python_Dv I do believe it returns None. Blocks of exceptions does not support the statement "return", so by default the function will return NoneObject
English
0
0
0
175
Prem Prakash
Prem Prakash@4EverPrem·
@Python_Dv 2 In try, except, else and finally construct, finally block is always executed. Here first try is executed and return 1. Then finally is executed and it returns and overwrites 1 thus printing 2
English
0
0
0
322
Paylaş