Re: Python: What Happens When This If Executes?

  • From: Jim Dunleavy <jim.dunleavy@xxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Wed, 03 Nov 2010 11:10:44 +0000

Hi Jim,

The feature is called comparison chaining and is equivalent to
if board[row[0]] == board[row[1]] and board[row[1]] == board[row[2]] and

  board[row[2]] != EMPTY:

except that the operands are only evaluated once.

It's covered in chapter 5 Expressions, of the Python reference.



--Jim





----- Original Message ----- 
From: Homme, James 
To: programmingblind@xxxxxxxxxxxxx 
Sent: Tuesday, November 02, 2010 2:42 PM
Subject: Python: What Happens When This If Executes?


Hi,

I understand that this statement compares three values to see if they are the 
same, and that they are not the value called Empty, which is a global variable 
filled with a space, but how does it do this?

 

if board[row[0]] == board[row[1]] == board[row[2]] != EMPTY:

 

Thanks.

 

Jim

 

Jim Homme,

Usability Services,

Phone: 412-544-1810. Skype: jim.homme

Internal recipients,  Read my accessibility blog. Discuss accessibility here. 
Accessibility Wiki: Breaking news and accessibility advice

 



--------------------------------------------------------------------------------
This e-mail and any attachments to it are confidential and are intended solely 
for use of the individual or entity to whom they are addressed. If you have 
received this e-mail in error, please notify the sender immediately and then 
delete it. If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.


----------------------------------------------------------------------------
"Ta an fhaisneis sa riomhphost seo (ceangaltain san aireamh) faoi run. 
Baineann se leis an te ar seoladh chuige  amhain agus ta se ar intinn go
bhfaighfidh siadsan amhain e agus gurb iadsan amhain a dheanfaidh breithniu
air. Mas rud e nach tusa an duine ar leis e, ta cosc iomlan ar aon fhaisneis
ata ann, a usaid, a chraobhscaoileadh, a scaipeadh, a nochtadh, a fhoilsiu, na
a choipeail . Seains gurb iad tuairimi pearsanta an udar ata san iomhphost
agus nach tuairimi FSS iad.

Ma fuair tu an riomhphost seo tri dhearmad, bheadh muid buioch da gcuirfea in
iuil don Deasc Seirbhisi ECT ar an nguthan ag +353 1 6352757  no ar an
riomhphost chuig service.desk@xxxxxx agus ansin glan an riomhphost seo ded'
choras." 


"Information in this email (including attachments) is confidential.  
It is intended for receipt and consideration only by the intended recipient.
If you are not an addressee or intended recipient, any use, dissemination,
distribution, disclosure, publication or copying of information contained in
this email is strictly prohibited.  Opinions expressed in this email may be
personal to the author and are not necessarily the opinions of the HSE.

If this email has been received by you in error we would be grateful if you 
could immediately notify the ICT Service Desk by telephone at +353 1 6352757 
or by email to service.desk@xxxxxx and thereafter delete this
e-mail from your system"
----------------------------------------------------------------------------

Other related posts: