Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.lang.python > #4279
| Message-ID | <qkXiBsNSqQznGMXUYakD1nUMo5w@jntp> (permalink) |
|---|---|
| Subject | Re: Python does what? |
| References | <aB5Wiwv-Cy3MCkoAA9RcNKuT36g@jntp> <67d08c89$0$5196$426a74cc@news.free.fr> |
| Newsgroups | fr.comp.lang.python |
| Date | 2025-04-19 16:12 +0000 |
| Organization | Nemoweb |
| From | Python <jp@python.invalid> |
Le 11/03/2025 à 21:18, Thomas Alexandre a écrit :
> 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.
$ cat what.py
#!/usr/bin/env python3
try:
exit(0)
finally:
exit(42)
$ ./what.py ; echo $?
42
Back to fr.comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll 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