0

I know there are many built-in functions in Python that we can use without calling import xxx first, e.g., map, range, len, etc.

Is there a way I can build such a function myself too? Ideally, I would like to define a function called my_func, and call my_func anywhere in my project without calling from xxx import my_func.

czxttkl
  • 446
  • 3
  • 14

1 Answers1

0
import builtins

def my_func(): ...

builtins.my_func = my_func

Now you can use it anywhere without importing.

Alex Hall
  • 33,530
  • 5
  • 49
  • 82