Path: ...!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Mild Shock Newsgroups: comp.lang.python Subject: Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) Date: Fri, 8 Nov 2024 02:40:56 +0100 Message-ID: References: <050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 8 Nov 2024 01:40:55 -0000 (UTC) Injection-Info: solani.org; logging-data="347404"; mail-complaints-to="abuse@news.solani.org" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.19 Cancel-Lock: sha1:BLstDVwn9CtsYSvj3izfL9G0BtM= X-User-ID: eJwNxsEBwCAIA8CVGkhQxoGi+4/Q3uvkgXgXQ0FdXRTBLutjWg/obXh4Zmf/Tc7u6Z6BC1StCaybFSPbyuMfRVEVHw== In-Reply-To: Bytes: 2031 Lines: 52 Well you can use your Browser, since JavaScript understand post and pre increment: > x = 5 5 > x ++ 5 > x = 5 5 > ++ x 6 So we have x ++ equals in Python: x + = 1 x - 1 And ++ x equals in Python: x += 1 x But I don't know how to combine an assignment and an expression into one expession. In JavaScript one can use the comma: > x = 5 5 > y = (x += 1, x - 1) 5 > x = 5 5 > y = (x += 1, x) 6 But in Python the comma would create a tuple. Lawrence D'Oliveiro schrieb: > On Thu, 07 Nov 2024 12:55:53 +0530, Annada Behera wrote: > >> I heard this behavior is because python's integers are immutable. > > Nothing to do with that. > >> ++x or x++ will redefine 5 to 6, which the interpreter forbids ... > > One of those is actually syntactically valid. > > It just won’t do what you expect it to do. >