python 单行注释/多行注释/代码间注释/特殊注释/"""doc String

1.单行注释
python中单行注释采用 #开头

点击(此处)折叠或打开

  1. #!/usr/bin/python
  2. #filename: searchengine.py
  3. #input: onne
  4. #output: none
  5. #writer: mail:15933533880@163.com

  6. class crawler:
  7.     """
  8.     This is a crawler class.
  9.     It contains the statement of some function
  10.     """
  11.     #initial crawler class
  12.     def __init__(self, dbname):
  13.         pass
  14.     
  15.     def __del__(self):
  16.         pass

  17.     def dbcommit(self):
  18.         pass
2.多行注释

然后python蛋疼的没有块注释,所以现在推荐的多行注释也是采用的 #

点击(此处)折叠或打开

  1. #!/usr/bin/python
  2. #filename: searchengine.py
  3. #input: onne
  4. #output: none
  5. #writer: mail:15933533880@163.com
3.代码间注释

点击(此处)折叠或打开

  1. class crawler:
  2.     #initial crawler class
  3.     def __init__(self, dbname):
  4.         pass
4.特殊注释

比如#! /usr/bin/python  这句注释的意思就是告诉LINUX/UNIX去找到python的翻译器,大部分文件都不需要这个,只在要求也执行的文件中添加。

关于蛋疼的中文编码:  # coding = utf-8    【注:这句代码蛋疼的必须放在第二行啊,而且多个空格都不行啊!】
5.python的福利!!

python在注释中有一个非常有用的东西是 doc String ,它可以用于模块、函数和类的描述:(其实总结起来都是类)下面是一个标准的方法注释

点击(此处)折叠或打开

  1. class crawler:
  2.     """
  3.     This is a crawler class.
  4.     It contains the statement of some function
  5.     """
  6.     #initial crawler class
  7.     def __init__(self, dbname):
  8.         pass
  9.     
  10.     def __del__(self):
  11.         pass

  12.     def dbcommit(self):
  13.         pass
"""三个引号是注释格式 这些注释保存在方法的__doc__属性中,可以打印显示。

猜你喜欢

转载自blog.csdn.net/warrior_zhang/article/details/50503391