1.python沒有char數(shù)據(jù)類型鳞陨。
2.字符串切片:
正索引:a[:],a[:3],a[2:],a[1,8,2]
負(fù)索引:a[-1],a[-2],a[:-2],a[-2:-1],a[:-1:-1]
正索引越界取最后一個(gè)元素
負(fù)索引越接會(huì)出錯(cuò)
不過需要注意的是 -0 實(shí)際上就是 0,所以它不會(huì)從右邊開始計(jì)數(shù)!
>>> word[-0]'H'# (since -0 equals 0)Out-of-range negative slice indices are truncated, but don't try this for single-element (non-slice) indices:負(fù)索引切片越界會(huì)被截?cái)?不要嘗試將它用于單元素(非切片)檢索
>>> word[-100:]'HelpA'
>>> word[-10]# errorTraceback (most recent call last):File "", line 1, in ?
IndexError: string index out of range
3.Python 字符串不可變。向字符串文本的某一個(gè)索引賦值會(huì)引 發(fā)錯(cuò)誤
>>> word[0] = 'x'Traceback (most recent call last):File "", line 1, in ?
TypeError: object does not support item assignmen