vendredi 7 août 2020

python - preprocessor function prints with wrong if condition value

If I define a function with a preprocessor like in C, and then call it inside an if, it runs even though the if should be false.

#define HELLO \
{ \
    print("hello world") \
}

i = 1
if i == 2:
    HELLO

This one prints hello.

If I do an ordinary function like this

def hello():
    print("hello world")

i = 1
if i == 2:
    hello()

then it doesn't do that.

Why is the difference please? I know the brackets are different but I tried both of them with and without the brackets and it doesn't make any difference.

Aucun commentaire:

Enregistrer un commentaire