Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this do what it does?

Tags:

python

syntax

I found this interesting item in a blog today:

def abc():
    try:
        return True
    finally:
        return False

print "abc() is", abc()

Can anyone tell why it does what it does?

Thanks, KR

like image 866
OddZon Avatar asked Aug 02 '10 17:08

OddZon


People also ask

What does it do or what does it does?

“Does” is used for singular subjects like “he,” “she,” “it,” “this,” “that,” or “John.” “Do” is used to form imperative sentences, or commands. Example: Do your homework. “Does” is never used to form imperative sentences.

Why do this or why does this?

The words “do” and “does” mean the same, that is, “to carry out or to perform an action.” “Do” is used in the first and second persons; “does” is used in the third person. 3. “Do” is used when referring to two or more persons or things while “does” is used when referring to a single person or thing.

Why does or why do grammar?

We use do/does or is/are as question words when we want to ask yes/no questions. We use does and is with third person singular pronouns (he, she, it) and with singular noun forms. We use do and are with other personal pronouns (you, we they) and with plural noun forms.

Why did or why do?

To make a question in the Past Tense in English we normally put the auxiliary DID at the beginning of the question or before the main subject. DID is used with regular AND irregular verbs in English. Both Do and Does in present tense questions become Did in past tense questions.


1 Answers

If the finally block contains a return or break statement the result from the try block is discarded

it's explained in detail in the python docu

like image 91
Nikolaus Gradwohl Avatar answered Oct 22 '22 12:10

Nikolaus Gradwohl