国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python的文檔

2019-11-06 08:22:48
字體:
來源:轉載
供稿:網友

Python的文檔

1、注釋

注釋以#號開頭,不會被執行。
>>> x = 10               # 定義一個變量x

2、dir()函數查看對象內所有屬性及方法。(1) 查看字符串類型。

>>> dir(str)['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__re(2) 查看os模塊。

>>> import os>>> dir(os)['F_OK', 'O_APPEND', 'O_BINARY', 'O_CREAT', 'O_EXCL', 'O_NOINHERIT', 'O_RANDOM', 'O_RDONLY', 'O_RDWR', 'O_SEQUENTIAL', 'O_SHORT_LIVED', 'O_TEMPORARY', 'O_TEXT', 'O_TRUNC', 'O_WRONLY', 'P_DETACH', 'P_NOWAIT', 'P_NOWAITO', 'P_OVERLAY', 'P_WAIT', 'R_OK', 'SEEK_CUR', 'SEEK_END', 'SEEK_SET', 'TMP_MAX', 'UserDict', 'W_OK', 'X_OK', '_Environ', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_copy_reg', '_execvpe', '_exists', '_exit', '_get_exports_list', '_make_stat_result', '_make_statvfs_result', '_pickle_stat_result', '_pickle_statvfs_result', 'abort', 'access', 'altsep', 'chdir', 'chmod', 'close', 'closerange', 'curdir', 'defpath', 'devnull', 'dup', 'dup2', 'environ', 'errno', 'error', 'execl', 'execle', 'execlp', 'execlpe', 'execv', 'execve', 'execvp', 'execvpe', 'extsep', 'fdopen', 'fstat', 'fsync', 'getcwd', 'getcwdu', 'getenv', 'getpid', 'isatty', 'kill', 'linesep', 'listdir', 'lseek', 'lstat', 'makedirs', 'mkdir', 'name', 'open', 'pardir', 'path', 'pathsep', 'pipe', 'popen', 'popen2', 'popen3', 'popen4', 'putenv', 'read', 'remove', 'removedirs', 'rename', 'renames', 'rmdir', 'sep', 'spawnl', 'spawnle', 'spawnv', 'spawnve', 'startfile', 'stat', 'stat_float_times', 'stat_result', 'statvfs_result', 'strerror', 'sys', 'system', 'tempnam', 'times', 'tmpfile', 'tmpnam', 'umask', 'unlink', 'unsetenv', 'urandom', 'utime', 'waitpid', 'walk', 'write']

3、help()方法查看函數或模塊用途的詳細說明。

>>> help(str.find)Help on method_descriptor:find(...)    S.find(sub [,start [,end]]) -> int        Return the lowest index in S where substring sub is found,    such that sub is contained within S[start:end].  Optional    arguments start and end are interpreted as in slice notation.        Return -1 on failure.

4、__doc__屬性

>>> print str.__doc__str(object='') -> stringReturn a nice string representation of the object.If the argument is a string, the return value is the same object.

5、自定義文檔自定義模塊文件sample.py。

"""Module SampleThis Module is for XXXX"""class Sample:	"""class documentation	class Sample	"""	def add(self, a, b):		"""function add		return (a + b)		"""		return a + b	def sub(self, a, b):		"""function sub		return (a - b)		"""		return a - b

導入sample文件,并進行操作。(1) dir方法

>>> import sample>>> dir(sample)                     # 模塊sample['Sample', '__builtins__', '__doc__', '__file__', '__name__', '__package__']>>> dir(sample.Sample)              # 模塊內的類Sample['__doc__', '__module__', 'add', 'sub']

(2) help方法

>>> help(sample)                    # 模塊sampleHelp on module sample:NAME    sampleFILE    e:/sample.pyDESCRIPTION    Module Sample    This Module is for XXXXCLASSES    Sample        class Sample     |  class documentation     |  class Sample     |       |  Methods defined here:     |       |  add(self, a, b)     |      function add     |      return (a + b)     |       |  sub(self, a, b)     |      function sub     |      return (a - b)

(3) __doc__方法

>>> print sample.__doc__            # 模塊sample的doc文檔Module SampleThis Module is for XXXX>>> print sample.Sample.__doc__     # 類Sample的doc文檔class documentation	class Sample
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 广德县| 兰州市| 惠州市| 弋阳县| 满城县| 增城市| 武清区| 客服| 沂水县| 赤城县| 雷山县| 海晏县| 中卫市| 日土县| 襄汾县| 三河市| 香河县| 澄江县| 龙口市| 兴国县| 洛隆县| 兴安县| 凉城县| 金门县| 平果县| 宁南县| 安平县| 红桥区| 满城县| 买车| 文化| 邵武市| 依安县| 大石桥市| 南通市| 平遥县| 双鸭山市| 田东县| 江津市| 金阳县| 牙克石市|