1. 程式人生 > >Python(28)_字串的索引和切片

Python(28)_字串的索引和切片

#-*-coding:utf-8-*-
'''
字串索引與切片
'''
# 索引
s = 'bowen'
s1 =s[0]   # b
print(s1)
# 切片,包頭不包尾
s2 = s[:3]
print(s2)  # bow

s3 = s[-1]
print(s3)  # n

s4 = s[-2]
print(s4) # e

s5 =s[:]
print(s5) # 複製

s6 = s[0:0]
print(s6)