Python help()函数和字符串.title()函数

3 投票
2 回答
3126 浏览
提问于 2025-04-15 20:20

为什么

import string;help(string.title) 

好像不管用,但

help(string.strip)

却能正常工作呢?

我遇到了这个错误:

追踪记录(最近的调用在最前面):
文件 "", 第 1 行,在 属性错误:'模块' 对象没有 属性 'title'

2 个回答

1

help(str.title) 这个命令看起来运行得很好。

2

title 是字符串类型(str)对象上的一个方法,而不是在 string 模块里的一个函数。这意味着你可以这样使用:"foo".title() 或者 str.title("foo"),但不能这样用:string.title("foo")

撰写回答