Python的help()函数和string.title()函数

3
为什么不会呢?
import string;help(string.title) 

看起来能够工作但是

help(string.strip)

运行正常吗?

我遇到了错误

最近的调用(最近的代码):
文件"", 行1, in AttributeError: 'module'对象没有 属性'title'

2个回答

2

title 方法属于 str 类型的对象,而不是 string 模块中的函数。这意味着你可以使用 "foo".title()str.title("foo"),但不能用 string.title("foo")


1

help(str.title) 看起来运行良好。


我需要阅读一些关于str和string之间区别的资料,谢谢。 - wp123
str是内置的,string是一个模块。 - ghostdog74
str 是字符串字面值的类型。 - Ignacio Vazquez-Abrams

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接