Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
Python: pass "not" as a lambda function

I need to pass a function as a parameter that works as the boolean "not". I tried something like this but it didn't work because not isn't a function.

theFunction(callback=not) # Doesn't work :(

I need to do the following, but I wonder if there exists any predefined function that does this simple job, so that I don't have to redefine it like this:

theFunction(callback=lambda b: not b, anotherCallback=lambda b: not b)

Note: I can't change the fact that I have to pass a function like this because it's an API call.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Yes, there is the operator module: https://docs.python.org/3.6/library/operator.html

import operator
theFunction(callback=operator.not_)
over 4 years ago · Santiago Trujillo Report

0

not is not a function, but a keyword. So that means you can not pass a reference. There are good reasons, since it allows Python to "short circuit" certain expressions.

You can however use the not_ (with underscore) of the operator package:

from operator import not_

theFunction(callback=not_, anotherCallback=not_)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!