Python学习笔记12
2016-04-25 21:35
597 查看
chapter_12
文档
注释
Python 用’#’号添加注释.Python的注释会保存到__doc__属性中
#docstrings.py """ Module documentation Words Go Here """ spam = 40 def square(x): """ function documentation can we have your liver then? """ return x**2 #square class Employee: "class documentation" pass print(square(4)) print(square.__doc__)
>>> import docstrings 16 function documentation can we have your liver then? >>> print(docstrings.__doc__) #显示文件注释 Module documentation Words Go Here >>> print(docstrings.square.__doc__) #显示函数注释 function documentation can we have your liver then? >>> print(docstrings.Employee.__doc__) #显示类注释 class documentation
常见编写代码的陷阱
别忘了冒号:一定要记住在复合语句首行末尾输入’:’从第一列开始,要确保顶层程序代码从第一列开始
缩进要一致
不要在Python中写C代码
使用简单的for循环,而不是while或range
要注意赋值语句中的可变对象,防止共享引用
不要期待在原处修改对象的函数会返回结果,如list.append,list.sort
一定要使用括号调用函数
不要在导入和重载中使用扩展名和路径
相关文章推荐
- Python分割list
- Python Logging模块-Logger,Handler,Formatter
- 用python将博客园的文章爬取到本地
- 聚类(一)pyspark 实现特征的ID化
- 【Python】set与frozenset的区别
- python10min系列之多线程下载器
- python 字典有序无序及查找效率,hash表
- Python代码分析工具之dis模块
- 推荐——基于python
- python实现单向链表
- Python - decorator
- Python学习二(生成器和八皇后算法)
- Python笔记(一)——int(),operator比较数值
- Python学习笔记1
- python learning-------装饰器
- python anaconda mkl
- Python 执行字符串表达式函数(eval exec execfile)
- 用 Python 打造你的 Eclipse
- Python学习笔记11
- python logging的简单使用2