zoukankan      html  css  js  c++  java
  • 零基础学python-14.3 python的文档资源:help函数

    python除了提供__doc__来查询文档字符串,还提供另外的一种方法来查询文档字符串:help

    下面是我们自己建立的一个类,使用help打印,形成相关的报表信息

    >>> class Test():
    	'这是一个测试类'
    	def helloworld():
    		'测试方法'
    		print('hello world')
    
    		
    >>> help(Test)
    Help on class Test in module __main__:
    
    class Test(builtins.object)
     |  这是一个测试类
     |  
     |  Methods defined here:
     |  
     |  helloworld()
     |      测试方法
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
    
    >>> 

    注意:在使用help的时候必须填写名称,不能使用空对象替代,例如:

    >>> help('')
    
    >>> help(str)
    Help on class str in module builtins:
    
    class str(object)
     |  str(object='') -> str
     |  str(bytes_or_buffer[, encoding[, errors]]) -> str
     |  
    

    但是,如果调用的是对象下面的方法,我们到可以通过空对象来实现

    >>> help(''.upper )
    Help on built-in function upper:
    
    upper(...) method of builtins.str instance
        S.upper() -> str
        
        Return a copy of S converted to uppercase.
    
    >>> help([].append )
    Help on built-in function append:
    
    append(...) method of builtins.list instance
        L.append(object) -> None -- append object to end
    
    >>> 

    还有一点需要注意的是,方法后面不带括号,带上括号将会查询不到,即便这个方法必须带上参数,也不用用上括号

    >>> help(''.upper() )
    
    >>> 

    >>> help(''.replace )
    Help on built-in function replace:
    
    replace(...) method of builtins.str instance
        S.replace(old, new[, count]) -> str
        
        Return a copy of S with all occurrences of substring
        old replaced by new.  If the optional argument count is
        given, only the first count occurrences are replaced.
    
    >>> 


    总结,这一章节我们简单说明了help的使用


    这一章节就说到这里,谢谢大家

    ------------------------------------------------------------------

    点击跳转零基础学python-目录

     



    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Excel求值表达式——太好用了
    CPU保护模式深入探秘
    用QT创建WINDOWS服务程序
    windows服务怎么向应用程序发消息(部署在同一台机,非SCOKET)
    TCP的流量控制和拥塞控制
    PHP:执行模型和内存模型
    Web API CSRF保护实现
    C#中易混淆的知识点
    字符串合并与拆分写法小结
    zabbix实现对磁盘动态监控
  • 原文地址:https://www.cnblogs.com/raylee2007/p/4896746.html
Copyright © 2011-2022 走看看