selfteaching / selfteaching/selfteaching-python-camp
Day05 为什么切割语法的时候取数是【2,4】?
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 151
- Forks
- 875
- PR merge metrics
- No merged PRs in 30d
Description
li=[1,2,4,3]
越界存取会造成IndexError
li[4] # 抛出IndexError
列表有切割语法
li[1:3] # => [2, 4]
取尾
li[2:] # => [4, 3]
取头
li[:3] # => [1, 2, 4]
隔一个取一个
li[::2] # =>[1, 4]
倒排列表
li[::-1] # => [3, 4, 2, 1]
可以用三个参数的任何组合来构建切割
li[始:终:步伐]
关于Learn python3 in Y Minutes学习过程中遇到的问题:为什么切割语法的时候取数是【2,4】?这个冒号的用法有点模糊。。。
@srvz
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the slicing examples in the issue and locate the corresponding Learn Python 3 in Y Minutes lesson. Clarify the meaning of start, stop, and step and why li[1:3] returns [2, 4], then verify that the surrounding examples remain consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100