The inspect module allows for many forms of introspection including this one, but note that it's only recommended to use such information for purposes such as debugging, not as part of your production code's functionality. See the docs for all details.