I'm trying to understand how I should read python documentation, for example given:
string.lstrip(s[, chars])
How should I read that? I know that brackets means optional, but that 's', what does it mean? Is there a page where it explains how the documentation was written?
1 Answer
It's not explictly defined in the documentation, but in
string.lstrip(s[, chars])
string is a Python module, it is not any string (e.g. it can't be "abc").
The parameter s is the string (e.g. it can be "abc") that you want to strip. It's mandatory, not optional.
The bracket-enclosed parameter is optional, it will be a string and its characters will be stripped from the string.
Some examples of how to call this function are:
import string
print string.lstrip("abc", "a") # "bc"
print string.lstrip(" abc") # "abc"
Note: Don't confuse with "abc".lstrip(). They are different functions with identical results. Also, read @user2357112's comment.
Edit: On my IDE I've just tested it and it actually shows what is s on the docs (pressing F2):
def lstrip Found at: string
def lstrip(s, chars=None):
"""lstrip(s [,chars]) -> string
Return a copy of the string s with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
"""
return s.lstrip(chars)
# Strip trailing tabs and spaces
sis the function's first parameter. There's nothing significant about the choice of the letters; it's just a name.str.lstripis something else. That method only takes a single, optional argument.stringmodule, not a string variable. It is literally "string".