繁体   English   中英

如何阅读Python文档

[英]How to read Python Documentation

我试图理解我应该如何阅读python文档,例如:
string.lstrip(s[, chars])
我应该怎么读? 我知道方括号的意思是可选的,但是那是什么意思? 是否有页面解释文档的编写方式?

在文档中没有明确定义,但在

string.lstrip(s[, chars])

string是一个Python模块,不是任何字符串(例如,不能为"abc" )。

参数s是要剥离的字符串(例如,可以是"abc" )。 这是强制性的,不是可选的。

方括号括起来的参数是可选的 ,它将是一个字符串,并且其字符将从字符串中去除。

如何调用此函数的一些示例是:

import string

print string.lstrip("abc", "a") # "bc"
print string.lstrip(" abc") # "abc"

注意:不要与"abc".lstrip()混淆。 它们是具有相同结果的不同功能。 另外,请阅读@ user2357112的注释。

编辑:在我的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM