Inconsistency in python help('string') versus help(list)?

后端 未结 5 761
旧时难觅i
旧时难觅i 2021-01-25 05:58

When I type help(\'string\') in the python interpreter I get information about the string class. There,upper() is indicated as a function. Yet I can on

5条回答
  •  滥情空心
    2021-01-25 06:22

    There's nothing wrong with what you see.

    >>> help('string')
    

    Will show you the string module documentation. And it looks like there's an upper function inside:

    >>> import string
    >>> string.upper('hello')
    'hello'
    

    I'd say that this upper is the same that is called if you do:

    >>> 'hello'.upper()
    

    But I'm not sure.

    Notice that a string '' is a str type not a string type. This means that you're probably looking for:

    >>> help('str')
    

    And here you'll see too the str.upper method.

提交回复
热议问题