I can't find .join function on http://docs.python.org/
I am looking for a library of built in functions for Python. In this excercise we use .join() function. I wanted to further examine what it does by looking up the documentation on docs.python.org but I can’t find it? Is there a reliable source where I can find all Python2.7 built in methods/functions?
string.join - so it’s in the document about string http://docs.python.org/2/library/string.html#string.join
if it was a built-in it would be join, not .join there’s always a name before the dot
and the built-ins are here: http://docs.python.org/2/library/functions.html
index of standard library: http://docs.python.org/2/library/index.html
and then there are 3rd party libraries, those docs are elsewhere
and this one is good to be aware about: http://www.python.org/dev/peps/pep-0008/
oh. oops. what you wanted was str.join, not string.join.. wasn’t even aware they both existed until now >_< THIS is str.join!
there’s a module called string a module is just another .py file that is run when you use the import statement the module string contains a couple of functions and classes a string is an instance of one of those classes (str or unicode) those classes contain methods, methods are functions that are defined in classes
str is a class string is a module
str.join is a method of the value type str string.join is a function in the module string
some code to show the difference between those two:
string.join(['bob', 'peter'], ' ') # evaluates into 'bob peter'
^join is a function in the module string, that’s why string needs to be imported, if instead doing:
from string import join then string. would not be necessary
' '.join(['bob', 'peter']) # evaluates into 'bob peter'
^’ ‘ is an instance of str, str contains the method join which can be called on ‘ ‘