• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

285
Views
Why does inspect() think map isn't built in?

The following code returns false

import inspect
print(inspect.isbuiltin(map))

But the map function is listed under "built-in" functions.

Why is it so?

about 3 years ago · Santiago Trujillo
1 answers
Answer question

0

The inspect.isbuiltin will only

Return true if the object is a built-in function or method.

The map builtin is a class, not a function or method:

>>> map
<class 'map'>

In fact, most "built-in functions" that return iterators are implemented as classes; calling them returns optimised instances instead of re-using some generic iterator class.

>>> zip  # zip iterator "function" is also a class
<class 'zip'>
>>> map(str, (1, 2, 34))  # map builds instances of map
<map object at 0x103fa34f0>

In addition, keep in mind that the term "built-in" has two meanings in Python:

  • A compiled object, i.e. built into the interpreter.
  • A member of the builtins module, available in every module.

While most builtins are compiled for speed, this is no necessity.

If you want to check whether a name is part of builtins, do so via the module:

>>> import builtins
>>> hasattr(builtins, "map")
True
>>> hasattr(builtins, "sum")
True
>>> hasattr(builtins, "reduce")
False
about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error