Young87

当前位置:首页 >个人收藏

Python3学习笔记-02(注释、编码、标识符、保留字)

一、单行注释

使用#号来定义单行注释,#右边的内容将不被解释,如下

#这里是单行注释
print("Hello World!")

二、多行注释

多行注释可以用三对单引号或者三对双引号来表示,如下

'''
这里是多行注释
这里是多行注释
这里是多行注释
'''

"""
这里是多行注释
这里是多行注释
这里是多行注释
"""
print("Hello World!")

三、编码

在默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串。当然也可以指定其他的编码方式,如下

# -*- coding: gbk -*-

四、标识符

必须是字母或者下划线开头

其他部分由字母、数字和下划线组成

对大小写敏感

在 Python 3 中,非 ASCII 标识符也是允许的

五、保留字

不能把保留字作为标识符的名称,在python的交互模式中输入如下命令,可以输出当前版本的所有保留字

C:\Users\Administrator>python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', '
finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'retu
rn', 'try', 'while', 'with', 'yield']

除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog

上一篇: 基于SpringBoot开发一套完整的项目(一)准备工作

下一篇: linux shell中的case语句用法 以及 case default设置

精华推荐