广告
返回顶部
首页 > 资讯 > 后端开发 > Python >python中3个帮助函数help,di
  • 506
分享到

python中3个帮助函数help,di

函数pythondi 2023-01-31 08:01:11 506人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

1 help函数:查看模块、函数、变量的详细说明: 查看模块 >>> help("modules") Please wait a moment while I gather a list of all ava

1 help函数:查看模块、函数、变量的详细说明:

  • 查看模块

>>> help("modules")

Please wait a moment while I gather a list of all available modules...

Basehttpserver      array               htmllib             sets
Bastion             ast                 Httplib             sgmllib
CDROM               asynchat            ihooks              sha
CGIHTTPServer       asyncore            imaplib             shelve
canvas              atexit              imghdr              shlex
ConfigParser        audiodev            imp                 shutil
Cookie              audioop             importlib           signal
DLFCN               axi                 imputil             site
Dialog              base64              inspect             sitecustomize
DocXMLrpcServer     bdb                 io                  smtpd
FileDialog          binascii            itertools           smtplib


  • 查看包

>>> help("JSON")
Help on package json:

NAME
    json

FILE
    /usr/lib/python2.7/json/__init__.py

MODULE DOCS
    http://docs.Python.org/library/json

DESCRIPTION
    JSON (javascript Object Notation) <http://json.org> is a subset of
    JavaScript syntax (ECMA-262 3rd edition) used as a lightweight data
    interchange fORMat.
    
    :mod:`json` exposes an api familiar to users of the standard library
    :mod:`marshal` and :mod:`pickle` modules. It is the externally maintained
    version of the :mod:`json` library contained in Python 2.6, but maintains
    compatibility with Python 2.4 and Python 2.5 and (currently) has
    significant performance advantages, even without using the optional C
    extension for speedups.
    
    Encoding basic Python object hierarchies::


  • 查看类

>>> help(json.JSONDecoder)
Help on class JSONDecoder in module json.decoder:

class JSONDecoder(__builtin__.object)
 |  Simple JSON <http://json.org> decoder
 |  
 |  Performs the following translations in decoding by default:
 |  
 |  +---------------+-------------------+
 |  | JSON          | Python            |
 |  +===============+===================+
 |  | object        | dict              |
 |  +---------------+-------------------+
 |  | array         | list              |
 |  +---------------+-------------------+
 |  | string        | unicode           |
 |  +---------------+-------------------+
 |  | number (int)  | int, long         |
 |  +---------------+-------------------+
 |  | number (real) | float             |
 |  +---------------+-------------------+
 |  | true          | True              |
 |  +---------------+-------------------+
 |  | false         | False             |


  • 查看函数:

>>> help(json.dump)
Help on function dump in module json:

dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, encoding='utf-8', default=None, **kw)
    Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
    ``.write()``-supporting file-like object).
    
    If ``skipkeys`` is true then ``dict`` keys that are not basic types
    (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
    will be skipped instead of raising a ``TypeError``.
    
    If ``ensure_ascii`` is false, then the some chunks written to ``fp``
    may be ``unicode`` instances, subject to normal Python ``str`` to
    ``unicode`` coercion rules. Unless ``fp.write()`` explicitly
    understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
    to cause an error.


2 dir函数:查看变量可用的函数或方法

>>> import sys
>>> dir(sys)
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', '_mercurial', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit', 'exitfunc', 'flags', 'float_info', 'float_repr_style', 'getcheckinterval', 'getdefaultencoding', 'getdlopenflags', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'gettrace', 'hexversion', 'last_traceback', 'last_type', 'last_value', 'long_info', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'py3kwarning', 'pydebug', 'setcheckinterval', 'setdlopenflags', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions']


3 type函数:查看变量的类型

<type 'module'>
>>> type (json.__name__)
<type 'str'>
>>> type (json.decoder)
<type 'module'>

4 退出python命令行

windows: ctrl+z 回车

linux:ctrl+d 

注:使用pydoc module 可查看模块的文档说明

--结束END--

本文标题: python中3个帮助函数help,di

本文链接: https://www.lsjlt.com/news/192403.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • python中3个帮助函数help,di
    1 help函数:查看模块、函数、变量的详细说明: 查看模块 >>> help("modules") Please wait a moment while I gather a list of all ava...
    99+
    2023-01-31
    函数 python di
  • python中怎么快速切换到函数帮助
    在python中查询函数帮助的方法查看模块下的所有函数import mathdir(math)查看模块下特定函数的信息import mathdir(math.sin)查询模块或模块下函数的使用帮助信息import mathmathmath....
    99+
    2022-10-23
  • Python函数在实际操作中获取帮助的方案是什么
    本篇文章为大家展示了Python函数在实际操作中获取帮助的方案是什么,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。Python函数作为计算机语言广泛应用的一种语言,如果你想在用Python编写运行H...
    99+
    2023-06-17
  • Python中有哪些强大的NumPy函数可以帮助您更好地处理数据?
    Python中的NumPy库是一个广泛使用的库,用于处理大型数组和矩阵。NumPy提供了许多强大的函数,可以帮助您更好地处理数据。在本文中,我们将介绍一些最常用的NumPy函数,以及它们如何帮助您更好地处理数据。 np.zeros n...
    99+
    2023-08-06
    numy 函数 bash
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作