Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
try_finally question
#1
hi
I saw the below code on the net:
def foo():
    try:
        return 1
    finally:
        return 2

    
k=foo()
print(k)
the result of running this code is 2( return result from finally). why is it? if the return in the try section does not run?
please explain.
another question that is not related to the above.
usually, when I enter this forum to see replies to my threads I go to forum>>my discussions. but there is not (I did not have seen until now) any object for creating a new thread there, so I have to go to home>>generall coding help>>post thread for creating a new thread.
is there an object or method in my discussions to create a new thread?
thanks
Reply


Messages In This Thread
try_finally question - by akbarza - Oct-07-2023, 11:22 AM
RE: try_finally question - by deanhystad - Oct-07-2023, 11:48 AM
RE: try_finally question - by akbarza - Oct-08-2023, 10:01 AM
RE: try_finally question - by snippsat - Oct-08-2023, 12:15 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020