[英]How to read Python Documentation
I'm trying to understand how I should read python documentation, for example given: 我试图理解我应该如何阅读python文档,例如:
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"
). string
是一个Python模块,不是任何字符串(例如,不能为"abc"
)。
The parameter s
is the string (eg it can be "abc"
) that you want to strip. 参数
s
是要剥离的字符串(例如,可以是"abc"
)。 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()
. 注意:不要与
"abc".lstrip()
混淆。 They are different functions with identical results. 它们是具有相同结果的不同功能。 Also, read @user2357112's comment.
另外,请阅读@ user2357112的注释。
Edit: On my IDE I've just tested it and it actually shows what is s
on the docs (pressing F2 ): 编辑:在我的IDE我只是测试它,它实际上显示的是
s
的文档(按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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.