python中[:-1]
来源:互联网 发布:软件缓存是什么意思 编辑:程序博客网 时间:2024/06/17 02:40
python中[:-1]:
It slices the string to omit the last character, in this case a newline character:
>>> 'test\n'[:-1]'test'
Since this works even on empty strings, it’s a pretty safe way of removing that last character, if present:
>>> ''[:-1]''
This works on any sequence, not just strings.
a[-1] # last item in the arraya[-2:] # last two items in the arraya[:-2] # everything except the last two items
>>> seq[:] # [seq[0], seq[1], ..., seq[-1] ]>>> seq[low:] # [seq[low], seq[low+1], ..., seq[-1] ]>>> seq[:high] # [seq[0], seq[1], ..., seq[high-1]]>>> seq[low:high] # [seq[low], seq[low+1], ..., seq[high-1]]>>> seq[::stride] # [seq[0], seq[stride], ..., seq[-1] ]>>> seq[low::stride] # [seq[low], seq[low+stride], ..., seq[-1] ]>>> seq[:high:stride] # [seq[0], seq[stride], ..., seq[high-1]]>>> seq[low:high:stride] # [seq[low], seq[low+stride], ..., seq[high-1]]
0 0
- python中[:-1]
- python【1】Python中常用的快捷键和BIF
- Python(1):在Python 中print的新用法
- c++中嵌入python入门1
- python中列表的pop、remove、-1
- C++中嵌入python入门1
- python分享-中阶(1)
- 1 Python中 _的作用
- python中删除不需要的字符1、
- python题目-----整数二进制中1个数
- Python 中括号的使用(1)
- Python :二进制中1的个数
- Python中@符号的用法-1
- Python 获取二进制中1的位置
- python中运行其他python
- 【Python语法】python中__name__
- Python中numpy中asarray
- Python中numpy中asarray
- [Java]servlet小结
- 算法导论 练习题 12.2-1
- AC自动机——HDU3065病毒侵袭持续中
- Struct库的使用
- 【jzoj5101】【GDOI2017 day2】【凡喵识图】【随机算法】【分组】
- python中[:-1]
- c#的partial用法
- 百度2017秋招-颜色反转
- python-setuptools : 依赖: python-pkg-resources (= 3.3-1ubuntu2) 但是 3.3-1ubuntu1 正要被安装
- mybatis快速入门
- Android lint工具
- 纯虚函数声明成private
- CSU 1120 病毒(dp最长公共序列)
- 强化学习系列<7>Deep Deterministic Policy Gradient (DDPG)