1. 程式人生 > >[第二章]Python字串切片示例

[第二章]Python字串切片示例

[第三章] Python使用字串切片示例

3.16 s = ‘hello’, t = ‘world’, s+= t, 則s、s[-1]、s[2:8]、s[::3]、s[-2::-1]、s[::-1]分別是多少?

>>>s = 'hello'
>>>t = 'world'
>>>s += t
>>>print(s)
helloworld
>>>s[-1]
'd'
>>>s[2:8]
'llowor'
>>>s[::3]
'hlod'
>>>s[-2
::-1] 'lrowolleh' >>>s[::-1] 'dlrowolleh'