Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.python > #4278

Re: Python does what?

From Thomas Alexandre <none@no.invalid>
Subject Re: Python does what?
Newsgroups fr.comp.lang.python
References <aB5Wiwv-Cy3MCkoAA9RcNKuT36g@jntp>
Organization 🍿🍺
Date 2025-03-11 19:18 +0000
Message-ID <67d08c89$0$5196$426a74cc@news.free.fr> (permalink)

Show all headers | View raw


Le Tue, 11 Mar 25 18:47:54 +0000, Python a écrit :

>>>> def what():
> ..     try:
> ..         return 12
> ..     finally:
> ..         return 42 ..
>>>> what()
> ? ? ?
> 
> 1. Essayer de prévoir

42

> 2. Vérifier

```
The return value of a function is determined by the last return statement 
executed. Since the finally clause always executes, a return statement 
executed in the finally clause will always be the last one executed
```
https://docs.python.org/3/reference/compound_stmts.html#finally-clause

Oui, c'est totalement contre-intuitif - particulièrement dans cet exemple.

-- 
"Ce qu'il faut au fond pour obtenir une espèce de paix avec les hommes,
(...) c'est leur permettre en toutes circonstances, de s'étaler, de se
vautrer parmi les vantardises niaises. Il n'y a pas de vanité
intelligente. C'est un instinct." - Céline

Back to fr.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python does what? Python <jp@python.invalid> - 2025-03-11 18:47 +0000
  Re: Python does what? Thomas Alexandre <none@no.invalid> - 2025-03-11 19:18 +0000
    Re: Python does what? Python <jp@python.invalid> - 2025-04-19 16:12 +0000

csiph-web