【发布时间】:2011-01-14 11:06:37
【问题描述】:
来自http://docs.python.org/library/string.html 的 Python 文档:
string.lstrip(s[, chars])返回删除前导字符的字符串副本。如果chars 被省略或
None,空白字符被删除。如果给定而不是None,chars 必须是字符串;字符串中的字符将从调用此方法的字符串的开头删除。"
Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> import string
>>> x = 'Hi'
>>> string.lstrip(x,1)
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
string.lstrip(x,1)
AttributeError: 'module' object has no attribute 'lstrip'
>>>
我在这里错过了什么?
【问题讨论】:
-
它应该给你 TypeError 因为 1 不是字符。
标签: python string python-3.x