1. 注释的作⽤
没有注释的代码
添加注释的代码
通过⽤⾃⼰熟悉的语⾔,在程序中对某些代码进⾏标注说明,这就是注释的作⽤,能够⼤⼤增强程序的可读性。
2. 注释的分类及语法
注释分为两类:
单⾏注释
和
多⾏注释
。
单⾏注释 ,只能注释⼀⾏内容,语法如下:
# 注释内容
多⾏注释
可以注释多⾏内容,⼀般⽤在注释⼀段代码的情况, 语法如下:
"""
第⼀⾏注释
第⼆⾏注释
第三⾏注释
"""
'''
注释1
注释2
注释3
'''
快捷键:
ctrl + /
示例代码:
单⾏注释:
# 输出hello world
print('hello world')
print('hello Python') # 输出(简单的说明可以放到⼀⾏代码的后⾯,⼀般习惯代码后⾯添加
两个空格再书写注释⽂字)
多⾏注释:
"""
下⾯三⾏都是输出的作⽤,输出内容分别是:
hello Python
hello itcast
hello itheima
"""
print('hello Python')
print('hello itcast')
print('hello itheima')
'''
下⾯三⾏都是输出的作⽤,输出内容分别是:
hello Python
hello itcast
hello itheima
'''
print('hello Python')
print('hello itcast')
print('hello itheima')
注意:解释器不执⾏任何的注释内容。