Path: ...!news.mixmin.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!pasdenom.info!from-devjntp Message-ID: JNTP-Route: nemoweb.net JNTP-DataType: Article Subject: Re: Python does =?UTF-8?Q?what=3F?= References: <67d08c89$0$5196$426a74cc@news.free.fr> Newsgroups: fr.comp.lang.python JNTP-HashClient: Gx-StWrMfh7YmekUx_Ca2Lb2vxU JNTP-ThreadID: QErA2ccb6ElCwQRHpnmZcJIlLfI JNTP-Uri: https://www.nemoweb.net/?DataID=qkXiBsNSqQznGMXUYakD1nUMo5w@jntp User-Agent: Nemo/1.0 JNTP-OriginServer: nemoweb.net Date: Sat, 19 Apr 25 16:12:53 +0000 Organization: Nemoweb JNTP-Browser: Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0 Injection-Info: nemoweb.net; posting-host="5ce6667f1c9f91894fad7e1589c8d2b44099634f"; logging-data="2025-04-19T16:12:53Z/9283498"; posting-account="190@nemoweb.net"; mail-complaints-to="julien.arlandis@gmail.com" JNTP-ProtocolVersion: 0.21.1 JNTP-Server: PhpNemoServer/0.94.5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-JNTP-JsonNewsGateway: 0.96 From: Python Bytes: 2051 Lines: 36 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