jeudi 30 avril 2020

Why if (integer) being evaluated as True?

In this piece of code why would line 6 execute with the conditional statement "if f(3):" wouldn't that just be essentially asking "if 3" since f(x) just returns x?

Also why does "not y" return False if y in this case is equal to 3?

1   def f(x):
2       return x
3   
4   def g(x, y):
5       if x(y):
6           return not y
7       return y
8   
9   x = 3
10  x = g(f, x)
11  f = g(f, 0)

Aucun commentaire:

Enregistrer un commentaire