How do you see the code of predefined (not defined by me) python functions? | Coursera Community
Coursera Header

How do you see the code of predefined (not defined by me) python functions?

  • 7 February 2019
  • 3 replies
  • 43 views

Badge +1
Just interested in how the code looks like

3 replies

Badge +1
So, for one prima is good the code predefinid, because the job fast. But for outher prisma i do know how are make.
This is one question that need to be better clean to us.
Userlevel 4
Badge +3
https://github.com/python/cpython
Userlevel 1
Badge +1
You can check hidden code for modules using inspect, but only after you import the particular module and then import the inspect module --- try help(inspect)


>>> import randint

>>> from inspect import getsource

>>> getsource(randint) # here i am going to explore code for package called `randint`


you can simply use help() command to get help about builtin functions as well its code.
for eg: if you want to see the code for str() , simply type - help(str)
it will return like this,


>>> help(str)

Help on class str in module __builtin__:


class str(basestring)

str(object='') -> string



Return a nice string representation of the object.

If the argument is a string, the return value is the same object.


hope that helps

Reply