1. python中字符串的格式
如下定义的变量a,存储的是数字类型的值
a = 100
如下定义的变量b,存储的是字符串类型的值
b = "hello world"
或者
b = 'hello world'
或者
b = '''hello world'''
b = '''hello
world'''
或者
b = """hello world"""
b = """hello
world"""
print(type(b)) # <class 'str'>
# 这样也可以输出多行
b = 'nish \n' \
'lkl'
print(b,type(b))
小总结:
- 单引号或者双引号或者三引号中的数据,就是字符串
- 字符串的类型是:str
<class 'str'>
- 如果字符串里面的内容只有一行,可以使用单引号或者双引号字符串;如果字符串里面的内容有多行,可以使用三引号字符串。