Why do most programming languages only have binary equality comparison operators?

前端 未结 24 804
一个人的身影
一个人的身影 2020-12-08 14:20

In natural languages, we would say \"some color is a primary color if the color is red, blue, or yellow.\"

In every programming language I\'ve seen, that translates

24条回答
  •  囚心锁ツ
    2020-12-08 15:01

    Two possibilities

    Java

    boolean isPrimary = Arrays.asList("red", "blue", "yellow").contains(someColor);
    

    Python

    a = 1500
    if  1 < a < 10 or  1000 < a < 2000:
         print "In range"
    

提交回复
热议问题