Python boolean expression syntax error

387 views Asked by At

Apparently, the following line is not valid Python syntax.

while (!is_int(1)):

How do I fix it?

Note: I don't know Python.

3

There are 3 answers

0
Fred Foo On BEST ANSWER

Boolean NOT is written not in Python:

while not is_int(1):

(Assuming you've implemented a function is_int.)

0
BioGeek On

Why define your own function is_int if you have the built-in function isinstance?

while not isinstance(1, int):
1
Sebastiano Merlino On

The correct syntax is:

while not is_int(1):
    ....

Where is_int can be implemented as:

def is_int(arg):
    return isinstance(arg, int)