[英]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.