默认情况下,Python 3 源码文件以 UTF-8 编码,在开始代码前,先声明编码格式
# -*- coding: utf-8 -*-
Python 的标准库提供了一个 keyword 模块,可以输出当前版本的所有关键字:
>>> 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', 'return', 'try', 'while', 'with', 'yield']
Python中单行注释以 # 开头
# 我是注释
print ("Hello,world!")
多行注释可以用多个 # 号,还有 ‘’’ 和 “”":
# 我是注释
#我也是注释
“”“我是一个多行注释”“”
‘’‘我也是多行注释’‘’
可以使用反斜杠 \ 来实现多行语句:
num = 1 + \
2 + \
3
①.Number(数字)
②.String(字符串)
③.List(列表)
④.Tuple(元组)
⑤.Set(集合)
⑥.Dictionary(字典)
字符串是 Python 中最常用的数据类型,可以使用引号( ’ 或 " )来创建字符串
str = 'Hello World!'
print 默认输出是换行的,如果要实现不换行需要在变量末尾加上 end=“”
x = 99
# 换行输出
print( x )
# 不换行输出
print( x, end=" " )