Which way can i see into python function

How can I see into the python function (for example abs() ), because I want to get inspiration from them to create the new function for myself?

It depends on the function. In the case of abs, in the case of the CPython implementation of Python, what it does is to call fabs from C++ and put the result into a Python’s float.

In the case of functions that are implemented in Python, you can do

import inspect
lines = inspect.getsource(foo)

where foo is the function.

Not true. That’s what happens for floats. And I don’t think CPython uses C++.

Is it C what is implemented in?

Ah, indeed. A tiny bit of C++, more C, and mostly Python

cppreference.com is still a fairly definitive reference for C. I’d love to know if there’s a better one that doesn’t require looking through an ISO technical standard.

Yes, that’s where I go as well if I want to look up a C function.

The other aspect is far more interesting, though. For example this of course doesn’t call fabs but calls my function:

class C:
    def __abs__(self):


Attempt This Online!

(Even in the small chunk identified as C++ code there, a fair bit of it is really C.)

Many editors let you Ctrl + click the function name to go to its definition. I think that’s the easiest way to explore python implementation. It only works if the function is implemented in python though, abs for example is written in C so it won’t work.