0

I have a function which returns true/false. Now I tried to use in a condicional, like this:

isOdd = lambda n: True if n%2 != 0 else False

if !isOdd(2): 
  print('Yey')

but I got SyntaxError: invalid syntax

how could I use ! in a function like this? it looks like this only works if:

if isOdd(2) == False: 
  print('Yey')
Sharki
  • 404
  • 4
  • 23

1 Answers1

2

I don't believe Python uses ! for negation like C does. Try

if not isOdd(2):
Daniel Walker
  • 6,380
  • 5
  • 22
  • 45