`
李灵晖-raylee
  • 浏览: 128676 次
博客专栏
Group-logo
从头认识java
浏览量:0
文章分类
社区版块
存档分类
最新评论

零基础学python-14.2 python的文档资源:文档字符串

 
阅读更多

这一章节我们来说说文档字符串:__doc__

文档字符串其实也是注释的一种,但是它一般放在模块文件、函数或者类语句的顶部,主要用来说明它们是干什么的,为什么这样做

python会自动封装这些文字,放到__doc__属性里面

>>> def test():
	'这是一个测试方法'
	print('hello world')

>>> test.__doc__
'这是一个测试方法'
>>> 

>>> class Test():
	'这是一个测试类'
	def helloworld():
		'测试方法'
		print('hello world')

		
>>> Test.helloworld ()
hello world
>>> Test.helloworld.__doc__
'测试方法'
>>> Test.__doc__
'这是一个测试类'
>>> 


下面,我们再来说说内置文档字符串

python的内部已经提供了大量的文档给我们,我们导入模块的时候,只需要打印这个模块的__doc__属性,我们就可以大概知道这个模块是干什么的,还有方法列表等

>>> import sys
>>> print(sys.__doc__)
This module provides access to some objects used or maintained by the
interpreter and to functions that interact strongly with the interpreter.

Dynamic objects:

argv -- command line arguments; argv[0] is the script pathname if known
path -- module search path; path[0] is the script directory, else ''
modules -- dictionary of loaded modules

displayhook -- called to show results in an interactive session
excepthook -- called to handle any uncaught exception other than SystemExit
  To customize printing in an interactive session or to install a custom
  top-level exception handler, assign other functions to replace these.

stdin -- standard input file object; used by input()
stdout -- standard output file object; used by print()
stderr -- standard error object; used for error messages
  By assigning other file objects (or objects that behave like files)
  to these, it is possible to redirect all of the interpreter's I/O.

last_type -- type of last uncaught exception
last_value -- value of last uncaught exception
last_traceback -- traceback of last uncaught exception
  These three are only available in an interactive session after a
  traceback has been printed.

Static objects:

builtin_module_names -- tuple of module names built into this interpreter
copyright -- copyright notice pertaining to this interpreter
exec_prefix -- prefix used to find the machine-specific Python library
executable -- absolute path of the executable binary of the Python interpreter
float_info -- a struct sequence with information about the float implementation.
float_repr_style -- string indicating the style of repr() output for floats
hash_info -- a struct sequence with information about the hash algorithm.
hexversion -- version information encoded as a single integer
implementation -- Python implementation information.
int_info -- a struct sequence with information about the int implementation.
maxsize -- the largest supported length of containers.
maxunicode -- the value of the largest Unicode code point
platform -- platform identifier
prefix -- prefix used to find the Python library
thread_info -- a struct sequence with information about the thread implementation.
version -- the version of this interpreter as a string
version_info -- version information as a named tuple
dllhandle -- [Windows only] integer handle of the Python DLL
winver -- [Windows only] version number of the Python DLL
__stdin__ -- the original stdin; don't touch!
__stdout__ -- the original stdout; don't touch!
__stderr__ -- the original stderr; don't touch!
__displayhook__ -- the original displayhook; don't touch!
__excepthook__ -- the original excepthook; don't touch!

Functions:

displayhook() -- print an object to the screen, and save it in builtins._
excepthook() -- print an exception and its traceback to sys.stderr
exc_info() -- return thread-safe information about the current exception
exit() -- exit the interpreter by raising SystemExit
getdlopenflags() -- returns flags to be used for dlopen() calls
getprofile() -- get the global profiling function
getrefcount() -- return the reference count for an object (plus one :-)
getrecursionlimit() -- return the max recursion depth for the interpreter
getsizeof() -- return the size of an object in bytes
gettrace() -- get the global debug tracing function
setcheckinterval() -- control how often the interpreter checks for events
setdlopenflags() -- set the flags to be used for dlopen() calls
setprofile() -- set the global profiling function
setrecursionlimit() -- set the max recursion depth for the interpreter
settrace() -- set the global debug tracing function

>>> 

总结,我们这一节主要描述了怎样使用文档字符串,以及简单讲述了内置文档字符串的使用


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

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

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




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

分享到:
评论

相关推荐

    python cookbook(第3版)

    15.15 C字符串转换为Python字符串 15.16 不确定编码格式的C字符串 15.17 传递文件名给C扩展 15.18 传递已打开的文件给C扩展 15.19 从C语言中读取类文件对象 15.20 处理C语言中的可迭代对象 15.21 诊断分析...

    Python 核心编程 第二版

     第6章 序列:字符串、列表和元组   6.1 序列   6.2 字符串   6.3 字符串和操作符   6.4 只适用于字符串的操作符   6.5 内建函数   6.6 字符串内建函数   6.7 字符串的独特特性   6.8 ...

    Python核心编程第二版

     1.6 Python文档   1.7 比较Python(Python与其他语言的比较)   1.8 其他实现   1.9 练习   第2章 快速入门   2.1 程序输出,print语句及“Hello World!”   2.2 程序输入和raw_input()内建...

    Python编程入门经典

    第1章 编程基础和字符串 3 1.1 编程与使用计算机的区别 3 1.1.1 编程的一致性 3 1.1.2 编程的可控性 4 1.1.3 程序要应对变化 4 1.1.4 小结 4 1.2 准备工作 4 1.2.1 在非Windows系统上安装 Python 3.1 5 1.2.2 使用...

    Python核心编程第二版(ok)

     1.6 Python文档   1.7 比较Python(Python与其他语言的比较)   1.8 其他实现   1.9 练习   第2章 快速入门   2.1 程序输出,1print语句及“HellocWorld!”   2.2 程序输入和raw_input()内建...

    像计算机科学家一样思考Python(第2版).pdf

    4.9 文档字符串 37 4.10 调试 38 4.11 术语表 38 4.12 练习 39 第5章 条件和递归 41 5.1 向下取整除法操作符和求模操作符 41 5.2 布尔表达式 42 5.3 逻辑操作符 42 5.4 条件执行 43 5.5 选择执行...

    Python核心编程(第二版).pdf (压缩包分2部分,第二部分)

     1.6 python文档   1.7 比较python(python与其他语言的比较)   1.8 其他实现   1.9 练习   第2章 快速入门   2.1 程序输出,print语句及“hello world!”   2.2 程序输入和raw_input()内建...

    python基础语法总结(超详细).pdf

    python基础语法总结(超详细) ⽬录 1、环境搭建 2、标识符 3、python保留字 4、注释和空⾏ 5、⾏与缩进 6、多⾏语句 7、声明变量 8、标准数据类型 8.1 Number(数字) 8.2 字符串(String) 8.3 List(列表) 8.4 ...

    Python Cookbook

    1.17 替换字符串中的子串-Python 2.4 34 1.18 一次完成多个替换 36 1.19 检查字符串中的结束标记 39 1.20 使用Unicode来处理国际化文本 40 1.21 在Unicode和普通字符串之间转换 43 1.22 在标准输出中打印...

    Python核心编程(第二版).pdf (压缩包分2部分,第一部分)

     1.6 python文档   1.7 比较python(python与其他语言的比较)   1.8 其他实现   1.9 练习   第2章 快速入门   2.1 程序输出,print语句及“hello world!”   2.2 程序输入和raw_input()内建...

    MySQL 5.1官方简体中文参考手册

    8.14. replace:字符串替换实用工具 8.15. mysql_zap:杀死符合某一模式的进程 9. 语言结构 9.1. 文字值 9.1.1. 字符串 9.1.2. 数值 http://doc.mysql.cn/mysql5/refman-5.1-zh.html-chapter/(第 8/24 页)2006-11...

    dive into python

    3.7.1. 字符串方法的历史注解 3.8. 小结 4. 自省的威力 4.1. 概览 4.2. 使用可选参数和命名参数 4.3. 使用 type、str、dir 和其它内置函数 4.3.1. type 函数 4.3.2. str 函数 4.3.3. 内置函数 4.4. 通过 ...

    Python基础教程(第3版)-201802出版-文字版

    久负盛名的 Python 入门经典针对 Python 3 全新升级十个出色的项目,让你尽快可以使用 Python 解决实际问题目录第 1章 快速上手:基础知识 ........................ 1 1.1 交互式解释器 .............................

    Python 科学计算

    1.1 Python 简介......................................1 1.2 安装软件包......................................2 1.2.1 Python(x,y)..................................... 2 1.2.2 Enthought Python ...

    快速学习-Python迭代器和生成器

    字符串,列表或元组对象都可用于创建迭代器 list=[1,2,3,4] it = iter(list) # 创建迭代器对象 print(next(it)) # 输出迭代器的下一个元素 print(next(it)) 14.2 迭代器遍历 list=[1,2,3,4] it = iter(list)

    《Python编程金典》读书笔记

    13. 字符串处理和正则表达式 13.1. 知识点 13.2. 良好的编程习惯 13.3. 性能提示 14. 文件处理和序列化 14.1. 知识点 14.2. 良好编程习惯 14.3. 常见编程错误 14.4. 性能提示 15. 可扩展标记语言(XML) 15.1. 知识...

    Android应用开发揭秘pdf高清版

    5.2.4 字符串绘制 5.2.5 图像绘制 5.2.6 图像旋转 5.2.7 图像缩放 5.2.8 图像像素操作 5.2.9 Shader类介绍 5.2.10 双缓冲技术 5.2.11 全屏显示 5.2.12 获得屏幕属性 5.3 动画实现 5.3.1 Tween动画 5.3.2 Frame动画 ...

    MySQL5.1参考手册官方简体中文版

    8.14. replace:字符串替换实用工具 8.15. mysql_zap:杀死符合某一模式的进程 9. 语言结构 9.1. 文字值 9.1.1. 字符串 9.1.2. 数值 9.1.3. 十六进制值 9.1.4. 布尔值 9.1.5. 位字段值 9.1.6. NULL值 9.2. 数据库、...

    Fuzzing_模糊测试--强制性安全漏洞发掘

    12.6 实例研究:REALPLAYER REALPIX格式化字符串漏洞 12.7 语言 12.8 小结 第13章 文件格式模糊测试:Windows平台上的自动化测试 13.1 Windows文件格式漏洞 13.2 FileFuzz的特性 13.2.1 创建文件 13.2.2 应用程序...

Global site tag (gtag.js) - Google Analytics