a == b == c triple comparison in C# vs Python -
how translate python code c#
l = [true, false] in l: b in l: c in l: print(a, b, c, a==b==c)
(which outputs this)
true true true true true true false false true false true false true false false false false true true false false true false false false false true false false false false true
into
void main() { list<bool> l = new list<bool> (){true, false}; foreach(var in l) { foreach(var b in l) { foreach(var c in l) { console.writeline(a.tostring()+" "+b.tostring()+" "+c.tostring()+" "+(a==b==c).tostring()); } } } }
which unfortunately doesn't work same way , outputs this:
true true true true true true false false true false true false true false false true false true true false false true false true false false true true false false false false
python has chained comparisons a == b == c
taken mean:
(a == b) , (b == c)
in c# a == b == c
evaluated as:
(a == b) == c
to translate python's a == b == c
c# use
a == b && b == c
Comments
Post a Comment