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

前端 未结 24 1009
一个人的身影
一个人的身影 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 14:42

    In python you can do something like this:

    color = "green"
    
    if color in ["red", "green", "blue"]:
        print 'Yay'
    

    It is called in operator, which tests for set membership.

提交回复
热议问题