Python学习笔记——切片操作
2012-02-25 21:45
316 查看
#slice[start:stop:step]
# 0 represent the left end of the sequence, -1 represents the right end of the sequence.
mystring = "my string"
#if the sign of the step is negative, then
#the default value of the start is -1, and the default value of the stop is zeor.
mystring[::-1] #'gnirts ym'
mystring[:3:-1] #'gnirt'
mystring[3::-1] #'s ym'
#if the sign of the step is positive, then
#the default value of the start is 0, and the defalut value of the stop is -1.
mystring[::1] #'my string'
mystring[:3:1] #'my '
mystring[3::1] #'string'
# start(0) ------- stop(-1), if the sign of the step is positive.
# stop(0) -------- start(-1), if the sign of the step is negative.
# 0 represent the left end of the sequence, -1 represents the right end of the sequence.
mystring = "my string"
#if the sign of the step is negative, then
#the default value of the start is -1, and the default value of the stop is zeor.
mystring[::-1] #'gnirts ym'
mystring[:3:-1] #'gnirt'
mystring[3::-1] #'s ym'
#if the sign of the step is positive, then
#the default value of the start is 0, and the defalut value of the stop is -1.
mystring[::1] #'my string'
mystring[:3:1] #'my '
mystring[3::1] #'string'
# start(0) ------- stop(-1), if the sign of the step is positive.
# stop(0) -------- start(-1), if the sign of the step is negative.
相关文章推荐
- Python 切片:利用切片操作,实现一个trim()函数,去除字符串首尾的空格
- [Python] 对字符串,列表的切片操作
- Python pandas库 数据切片 行列操作
- Python字符串切片操作知识详解
- python学习笔记(七)——文件和目录操作
- go语言笔记——切片函数常见操作,增删改查和搜索、排序
- python学习笔记之os.path系统文件夹的操作
- R 语言 数据切片,对每个切片组分别操作
- numpy多维数组的切片操作
- 深入解析Python中的list列表及其切片和迭代操作
- python中的切片操作
- Python 序列的切片操作与技巧
- 详解Python中的__getitem__方法与slice对象的切片操作
- torch Tensor学习:切片操作
- JS数组操作(数组增加、删除、翻转、转字符串、取索引、截取(切片)slice、剪接splice、数组合并)
- python学习笔记——文件操作
- 网页切片技术的全面理解与操作过程
- 关于序列切片的一些操作说明
- Python的切片操作
- Python学习笔记(3)-操作列表