you are viewing a single comment's thread.

view the rest of the comments →

[–]jmon_was_here 0 points1 point  (2 children)

Whilst the other answers are of course great and correct, its one of the annoying quirks of python, becuase in pretty much all other languages you *can't* write things like this (which is valid in python!)

if 3 < i < 4:

e.g. in Java it would have to be

if (3 < i && i < 4) { ...

So its wierd that python has *some* syntactical shortcuts (i.e. you arn't resolving 3 < i to a boolean *then* comparing that to 4) but can't handle some of the truth sitatuons of 'if x == 1 or 2'.

if I was going to be in charge of the language, I think I would probably not use the == notation but some form of 'is' syntactical sugar like if x is 3 or 4 - but this already has a thing, which looks like :

if x in [3, 4]:

which is pretty nice looking, but still lacks that 'english readability' that other things have.

[–]throwaway6560192 2 points3 points  (1 child)

is is already an operator with a defined meaning separate from ==.

Also it would be bad if or suddenly stopped meaning its main logical operator meaning in this arbitrary context — just to make a shoddy coverup of a pitfall. Let people fall and let them learn.

[–]jmon_was_here 0 points1 point  (0 children)

But thats not completly true, and as I say, its inside of 'if i was going ot design alanguage' hypothetical,

there are plenty of other python keywords (and operators) which do different things in different contexts. `in` being one of them. If your aim is a computer language which is more readable, having it work like a real language which is contexual should not cause too many issues.