[Tutor] Conditional Statement without if statement?

Dennis Lee Bieber wlfraed at ix.netcom.com
Tue Feb 8 17:41:19 EST 2022


On Tue, 8 Feb 2022 11:14:44 -0800, Alex Kleider <alexkleider at gmail.com>
declaimed the following:

>(p10) alex at X1:~/Git/Club/Guides$ python
>Python 3.10.0 (default, Nov 16 2021, 13:37:55) [GCC 8.3.0] on linux
>Type "help", "copyright", "credits" or "license" for more information.
>>>> x = 40 or 60
>>>> x
>40
>>>>

	The concise statement is that for a sequence of

OR		the first non-false ends the comparison and is returned
		if all are false, the last one is returned
		(false commonly being: False, 0, 0.0, (), [], "", {})

AND	the first false ends the comparison and is returned
		if all are non-false, the last is returned

>>> [] or 0 or 30 or True
30
>>> 30 and True and [] and (1, 3)
[]
>>> 
>>> [] or 0 or () or {}
{}
>>> 30 and True and [None] and (1, 3)
(1, 3)
>>> 


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/



More information about the Tutor mailing list