一、注释

确保对模块, 函数, 方法和行内注释使用正确的风格

单行注释以 # 开头

# 这是一个注释

print("Hello, World!")

单引号(''')

#!/usr/bin/python3

'''

这是多行注释,用三个单引号

这是多行注释,用三个单引号

这是多行注释,用三个单引号

'''

print("Hello, World!")

双引号(""")

#!/usr/bin/python3

"""

这是多行注释,用三个单引号

这是多行注释,用三个单引号

这是多行注释,用三个单引号

"""

print("Hello, World!")

二、DIR

语法:dir([object])

说明:

当不传参数时,返回当前作用域内的变量、方法和定义的类型列表。

>>> dir()

['__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']

>>> a = 10 #定义变量a

>>> dir() #多了一个a

['__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'a']

当参数对象是模块时,返回模块的属性、方法列表。

>>> import math

>>> math

>>> dir(math)

['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']

当参数对象是类时,返回类及其子类的属性、方法列表。

>>> class A:

name = 'class'

>>> a = A()

>>> dir(a) #name是类A的属性,其他则是默认继承的object的属性、方法

['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'name']

当对象定义了__dir__方法,则返回__dir__方法的结果

>>> class B:

def __dir__(self):

return ['name','age']

>>> b = B()

>>> dir(b) #调用 __dir__方法

['age', 'name']

三、__doc__

将文档写在程序里,是LISP中的一个特色,Python也借鉴过。每个函数都是一个对象,每个函数对象都是有一个__doc__的属性,函数语句中,如果第一个表达式是一个string,这个函数的__doc__就是这个string,否则__doc__是None。

>>> def testfun():

"""

this function do nothing , just demostrate the use of the doc string .

"""

pass

>>> testfun.__doc__

'\nthis function do nothing , just demostrate the use of the doc string .\n'

>>> #pass 语句是空语句,什么也不干,就像C语言中的{} , 通过显示__doc__,我们可以查看一些内部函数的帮助信息

>>> " ".join.__doc__

'S.join(iterable) -> str\n\nReturn a string which is the concatenation of the strings in the\niterable. The separator between elements is S.'

>>>

四、help

语法:help([object])

说明:

在解释器交互界面,不传参数调用函数时,将激活内置的帮助系统,并进入帮助系统。在帮助系统内部输入模块、类、函数等名称时,将显示其使用说明,输入quit退出内置帮助系统,并返回交互界面。

>>> help() #不带参数

Welcome to Python 3.5's help utility!

If this is your first time using Python, you should definitely check out

the tutorial on the Internet at

Enter the name of any module, keyword, or topic to get help on writing

Python programs and using Python modules.  To quit this help utility and

return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type

"modules", "keywords", "symbols", or "topics".  Each module also comes

with a one-line summary of what it does; to list the modules whose name

or summary contain a given string such as "spam", type "modules spam".

#进入内置帮助系统  >>> 变成了 help>

help> str #str的帮助信息

Help on class str in module builtins:

class str(object)

|  str(object='') -> str

|  str(bytes_or_buffer[, encoding[, errors]]) -> str

|

|  Create a new string object from the given object. If encoding or

|  errors is specified, then the object must expose a data buffer

|  that will be decoded using the given encoding and error handler.

|  Otherwise, returns the result of object.__str__() (if defined)

|  or repr(object).

|  encoding defaults to sys.getdefaultencoding().

|  errors defaults to 'strict'.

|

|  Methods defined here:

|

|  __add__(self, value, /)

|      Return self+value.

................................

help> 1 #不存在的模块名、类名、函数名

No Python documentation found for '1'.

Use help() to get the interactive help utility.

Use help(str) for help on the str class.

help> quit #退出内置帮助系统

You are now leaving help and returning to the Python interpreter.

If you want to ask for help on a particular object directly from the

interpreter, you can type "help(object)".  Executing "help('string')"

has the same effect as typing a particular string at the help> prompt.

# 已退出内置帮助系统,返回交互界面 help> 变成 >>>

在解释器交互界面,传入参数调用函数时,将查找参数是否是模块名、类名、函数名,如果是将显示其使用说明。

>>> help(str)

Help on class str in module builtins:

class str(object)

|  str(object='') -> str

|  str(bytes_or_buffer[, encoding[, errors]]) -> str

|

|  Create a new string object from the given object. If encoding or

|  errors is specified, then the object must expose a data buffer

|  that will be decoded using the given encoding and error handler.

|  Otherwise, returns the result of object.__str__() (if defined)

|  or repr(object).

|  encoding defaults to sys.getdefaultencoding().

|  errors defaults to 'strict'.

|

|  Methods defined here:

|

|  __add__(self, value, /)

|      Return self+value.

|

***************************

五、标准手册集

www.python.org

python退出帮助系统_Python基础(09):帮助相关推荐

  1. python退出帮助系统_Python退出脚本并返回Main

    我试图制作一个简单的基于文本的游戏来提高我对Python的了解,并且我在另一个Python文件中创建了一个小的战斗系统.我调用这个系统的方法是导入文件,然后调用start函数.我遇到的问题实际上是让脚 ...

  2. python如何搭建环境_Python基础环境如何搭建

    python基础环境搭建确实也是一大难题,就让扣丁为大家归纳总结重点知识,在大家的学习中,希望可以助大家一臂之力.其实Python的环境搭建说难也不难,说简单也不简单.主要有以上几点. 1.Pytho ...

  3. python退出循环快捷_python退出循环的方法

    break 语句 Python break语句,就像在C语言中,打破了最小封闭for或while循环. break语句用来终止循环语句,即循环条件没有False条件或者序列还没被完全递归完,也会停止执 ...

  4. python中ijust函数_Python基础

    脚本运行Windows 下需将python加入的系统变量中: Linux 下需添加头部#! /usr/bin/enc python print('Hello World!') 循环 for 循环 fo ...

  5. python 退出自定义函数_python通过自定义异常,提前退出方法

    python退出的操作,搜索后都是return.exit()等 return:退出一个方法,并返回一个值 exit():退出python 想要实现的功能: 方法A中调用多个方法,方法B.方法C..., ...

  6. python成绩查询系统_Python爬虫实战:登录教务系统查成绩

    本文记录我用Python登录教务系统查询成绩的过程.手动输入验证码,简单获取成绩页面.后续将可能更新自动识别验证码登录查询 前期准备 本爬虫用到了Python的Requests库和BeautifulS ...

  7. python编写超市销售系统_Python基础项目:超市商品销售管理系统

    Python基础项目:超市商品销售管理系统 发布时间:2020-07-12 09:11:58 来源:51CTO 阅读:991 作者:nineteens 需求分析: 超市销售管理系统功能 1.欢迎用户使 ...

  8. 零基础python自动化办公系统_python自动化办公?学这些就够用了

    知乎上有人提问:用python进行办公自动化都需要学习什么知识呢? 这可能是很多非IT职场人士面临的困惑,想把python用到工作中,却不知如何下手? python在自动化办公领域越来越受欢迎,批量处 ...

  9. python在线投票系统_Python开发基础-项目实训-在线投票系统.pptx

    项目实训-在线投票系统本章任务/30完成"在线投票系统"添加投票候选人删除候选人为候选人投票按序号投票删除投票输出统计信息--本章目标/30理解程序的基本概念会使用顺序.选择.循环 ...

最新文章

  1. 基于Sql Server 2008的分布式数据库的实践(一)
  2. 【安装PHP】如何在openSUSE42.1下编译安装PHP7
  3. 【Android 安装包优化】使用 lib7zr.so 动态库处理压缩文件 ( jni 中 main 函数声明 | 命令行处理 | jni 调用 lib7zr.so 函数库处理压缩文件完整代码 )
  4. dreamweaver 正则表达式为属性值加上双引号_Python正则表达式(一)
  5. Antd Vue 组件库之Table表单
  6. Linq:使用Take和Skip实现分页
  7. Asterisk目录结构如下
  8. Service,测试
  9. 软考资料-软件设计师
  10. opencv中对图片阀值的操作
  11. 训练集和测试集损失函数
  12. Word类报表实例 - 质量检测报告
  13. c51单片机时钟程序汇编语言,51单片机时钟汇编程序
  14. camera 测光模式 和 实际应用
  15. svg基础+微信公众号交互(一)
  16. VC++6.0安装、编译NTL类库
  17. javax.faces.webapp.FacesServlet
  18. 【Unity小功能开发实战教程】制作跟随倒计时变化的进度条
  19. android 10系统下载地址,Android 10正式版
  20. React 中 TypeScript 和装饰器及 Hooks

热门文章

  1. 设计导航网,全心全意为设计师服务的导航网站!
  2. 电商页面设计排版没有思路?可临摹PSD分层模板,诠释基础版式大招帮你轻松搞定!
  3. NVIDIA Tesla K40C 和 AMD Firepro W8100 的对比
  4. Linux内核协议栈-一个socket的调用过程,从用户态接口到底层硬件
  5. 一次 group by + order by 性能优化分析
  6. java 判断是不是微信打开_Java判断浏览器是微信还是支付宝
  7. Python List:一文彻底粉碎列表
  8. 分类算法python程序_分类算法——k最近邻算法(Python实现)(文末附工程源代码)...
  9. mpandroidchart 设置x轴数据_Flowjo软件下的流式数据基本分析
  10. OpenCv之图像二值化(笔记12)