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

后端 未结 5 857
旧时难觅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:30

    You are creating an instance of that object and then calling help on that instance.

    So these all work:

    help(1)
    help({})
    help([])
    help('')
    help(dir)
    help(help)
    

    Help grabs the docstring for that instance, and gives it back to you. When you create your own objects, you can put in useful docstrings or whatever you want.

提交回复
热议问题