Python中的代码注释

时间:2021-11-29 04:25:49

为什么要使用注释?

1. 方便自己查看写过的代码  2. 互联网人才流动大,为了项目能更好维护,需要适当写注释。

 

Python的注释符

1. 单行注释 #

1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3
4 #定义一个函数,用来输出Hello,Mary字符串。
5 def sayHello():
6 print('hello','Mary',sep=',',end='\n',flush=True)

2. 多行注释 使用三个单引号 '''内容'''  也可以使用三个双引号 """内容"""

1 '''
2 输出 Hello,Mary\t
3
4 '''
5 def sayHello():
6 print('Hello','Mary',sep=',',end='\t',flush=True)