字符串

单行和多行字符串

# 在python里 单引号 双引号效果是一样的
a='aa'
b="aa"

# 多行字符串
c = ''' aaa
bbb
ccc
'''

d = """ aaa
bbb
ccc
"""

字符串的截取

# 字符串截取

e ="hello world, nice to see you"

# 1, 截取单个字符
print(e[0]) # h
print(e[1]) # e

# 切片 
# 2. 截取substring
print(e[1:])   # ello world, nice to see you
print(e[1:-1]) # ello world, nice to see yo

print(e[:-1])  # hello world, nice to see yo

print(e[1:0]) # 不会打印任何东西

# 无论右边给值多大,只会取到最右边,等价于e[1:]
print(e[1:100]) # ello world, nice to see you

results matching ""

    No results matching ""