字符串类型有三种表达方式:
start = 'hello world!'
language = "Python"
article1 = '''
This is a long article:
Hello World!
'''
article2 = """
This is another long artice:
Hello World!!
"""
注意:
'''
This is a multiline
comment.
'''
"""
This is also a mutiline
comment.
"""
s1 = 'i "like" you'
s2 = "you 'like' me"
s3 = '''
good 'morning'
good "afternoon"
good """evening"""
'''
s1 = 'i \n like \n you'
s2 = r'i \n like \n you'
Python中的数字类型有四种:
v1 = 256 # int
v2 = 3.14 # float
v3 = 0x10 # 16进制
v4 = 3+5j # complex
布尔类型只有两种形式:真和假。在python2中使用1代表真,0代表假;在python3中使用True和False代表真假。
v1 = True
v2 = False
列表用于表示一系列的数据。列表使用中括号[ ] 进行定义,并且每个数据使用逗号 , 进行分隔。列表中存储的数据可以是任意类型,列表中存储的每一组数据成为元素。
varlist = [15, 'hello', 3.14, 3+5j, "good"]
列表中的元素可以通过下标获取,从左往右数第一个元素的下标是0,第二个元素下标是1,以此类推ÿ