I wanted to see how a math.py
function was implemented, but when I opened the file in PyCharm I found that all the functions are empty and there is a simple pass
. For example:
def ceil(x): # real signature unknown; restored from __doc__ """ ceil(x) Return the ceiling of x as a float. This is the smallest integral value >= x. """ pass
I guess it is because the functions being used are actually from the C standard library. How does it work?
The pass statement is used as a placeholder for future code. When the pass statement is executed, nothing happens, but you avoid getting an error when empty code is not allowed. Empty code is not allowed in loops, function definitions, class definitions, or in if statements.
So pass simply means to do nothing and just go on with processing the next line. Summary: return None is (or can imagined to be) always implicitly added below the last line of every function definition. It can also only appear in functions and immediately exits them, returning a value (or None as default).
The break and continue statements in Python are used to skip parts of the current loop or break out of the loop completely. The break statement can be used if you need to break out of a for or while loop and move onto the next section of code.
The correct answer is Functions are reusable pieces of programs. Explanation: The correct statement is that Functions are reusable pieces of programs. They allow you to give a name to a block of statements, allowing you to run that block using the specified name anywhere in your program and any number of times.
PyCharm is lying to you. The source code you're looking at is a fake that PyCharm has created. PyCharm knows what functions should be there, and it can guess at their signatures using the function docstrings, but it has no idea what the function bodies should look like.
If you want to see the real source code, you can look at it in the official Github repository in Modules/mathmodule.c
. A lot of the functions in there are macro-generated thin wrappers around C functions from math.h
, but there's also a bunch of manually-written code to handle things like inconsistent or insufficient standard library implementations, functions with no math.h
equivalent, and customization hooks like __ceil__
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With