Path: csiph.com!pasdenom.info!from-devjntp Message-ID: JNTP-Route: nemoweb.net JNTP-DataType: Article Subject: Re: Documentaire References: <68b70406$0$12947$426a34cc@news.free.fr> <1098bro$tio6$1@dont-email.me> Newsgroups: fr.comp.lang.python JNTP-HashClient: EO1Ins9iaFQuiuEIMaLBxeNak6Q JNTP-ThreadID: PbrDAHBRZ_88th5__jbP7k5edTE JNTP-Uri: https://www.nemoweb.net/?DataID=UualazIty7WwmMfX8vT6a6YeZg4@jntp User-Agent: Nemo/1.0 JNTP-OriginServer: nemoweb.net Date: Wed, 03 Sep 25 10:08:33 +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="233e0d765cbd3f20c14f1473f60a5416b01a34db"; logging-data="2025-09-03T10:08:33Z/9433827"; 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 Xref: csiph.com fr.comp.lang.python:4314 Le 03/09/2025 à 05:15, Dominique a écrit : > Le 02/09/2025 à 17:11, Python a écrit : > >>>>> all( (_  := x) % 2 == 0 for x in (0, 2, 4, 7, 9, 8)) >> False >>>>> _ >> 7 >> > > Je ne comprends pas cette formulation ? Help !) ( _:= x ) % 2 = 0 a la même valeur que x % 2 == 0 donc True si x est pair et False sinon. Au passage il y a un effet de bord : stocker la valeur courante de x dans _ (un nom quasiment comme un autre, peu expressif car on le réutilise tout de suite après une seule fois) Le code vérifie si tous les éléments d'un itérable sont pairs. Si ce n'est pas le cas on peut récupérer la valeur qui a rendu all( ... ) faux. Je me sers souvent de ce genre d'expression pour tester si tous les éléments d'un itérable sont bien du bon type : if not all( isinstance(_ := item, ...) for item in collection ): raise TypeError(f"Bad type: {_!r} ({type(_).__name__})")