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

256
Views
Python: pase "no" como una función lambda

Necesito pasar una función como parámetro que funcione como el booleano "no". Intenté algo como esto pero no funcionó porque not es una función.

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

Necesito hacer lo siguiente, pero me pregunto si existe alguna función predefinida que haga este trabajo simple , para que no tenga que redefinirla así:

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

Nota: no puedo cambiar el hecho de que tengo que pasar una función como esta porque es una llamada a la API.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Sí, existe el módulo de operator : https://docs.python.org/3.6/library/operator.html

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

0

not es una función , sino una palabra clave. Entonces eso significa que no puedes pasar una referencia. Hay buenas razones, ya que le permite a Python " cortocircuitar " ciertas expresiones.

Sin embargo, puede usar el not_ (con guión bajo) del paquete del operator :

 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!