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?
It's not explictly defined in the documentation, but in
string.lstrip(s[, chars])
string
is a Python module, it is not any string (eg it can't be "abc"
).
The parameter s
is the string (eg 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.