Confusion about x < y <= z in python -


this question has answer here:

i'm newbie in python. have 3 variables x, y, z int. have comparison 3 variables in if condition. i'm confused following code result.

the expression x < y <= z evaluates false.

let's assume x = 10, y = 5 , z = 0. if x < y become false, false <= 0 become true. but output false. why?

my python script:

#!/usr/bin/python  x = 10 y = 5 z = 0  if (x < y < z):         print"true" else:         print"false" 

the document say:

comparisons can chained arbitrarily; example, x < y <= z equivalent x < y , y <= z, except y evaluated once (but in both cases z not evaluated @ when x < y found false).

x < y <= z neither means (x < y) <= z nor x < (y <= z). x < y <= z equivalent x < y , y <= z, , evaluates left-to-right.

logical and not have associativity in python unlike c , c++. there separate rules sequences of kind of operator , cannot expressed associativity.

x < y , y <= z evaluates second argument if first 1 true because and short-circuit operator.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -