Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Python help

Name: Anonymous 2010-10-17 12:08

if operator != ("add"|"sub"):
    print ("Invalid Operator")

Basically I want to check if operator has anything other than "add" or "sub" assigned to it, but python 2.6 is saying

TypeError: unsupported operand type(s) for |: 'str' and 'str'

How should I check if operator is anything other than add or sub?

Name: Anonymous 2010-10-17 16:13

if not operator in ("add", "sub"):
    print ("Invalid Operator")

Name: Anonymous 2010-10-17 18:05

>>8
That parses to more tokens internally than the canonical
if operator not in ("add", "sub"):
    print("Invalid Operator")

Using the multi-word not in operator is more efficient[citation needed] than an in operator being later negated by a not operator.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List