【问题标题】:Python help() function and the string.title functionPython help() 函数和 string.title 函数
【发布时间】:2011-01-26 16:10:54
【问题描述】:

为什么没有

import string;help(string.title) 

似乎可以工作,但是

help(string.strip)

工作正常吗?

我得到了错误

回溯(最近一次通话最后一次):
文件“”,第 1 行,在 AttributeError:“模块”对象没有 属性“标题”

【问题讨论】:

    标签: python


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      help(str.title) 似乎工作得很好。

      【讨论】:

      • str 和 string 之间一定有某种区别,我需要了解一下,谢谢。
      • str 是内置的,string 是一个模块
      • str 是字符串字面量的类型。
      猜你喜欢
      • 2011-12-07
      • 1970-01-01
      • 2021-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多