Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do some of functions have pass [closed]

In (some) python libraries, when i look up the code, i see a bunch of functions or class methods which are written like this:

def funcName():
    pass

I just want to know how those functions DO stuff even though they only have pass which means that the function should do nothing.

like image 769
IssUseless Avatar asked Nov 21 '25 16:11

IssUseless


2 Answers

For user-defined functions, pass means doing nothing, but for some library functions (including third-party libraries), they usually mean that their logic is not written in pure Python code, such as NumPy and Python standard library, in order to pursue efficient operation, most functions are written in C language, and provides the corresponding Python interface.

More detailed answer

like image 148
Mechanic Pig Avatar answered Nov 24 '25 05:11

Mechanic Pig


Functions in python syntactically can't be empty. That's why you need to populate them, usually with pass

Sometimes, functions are declared, but purposely left empty. Then, they can be used in the default implementations, but possibly overridden by classes extending (inheriting) the library class.

like image 27
dominickque Avatar answered Nov 24 '25 06:11

dominickque



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!