Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson1_1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2c86837e
authored
Feb 24, 2020
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
9c853558
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
1.py
1.py
View file @
2c86837e
...
...
@@ -109,23 +109,25 @@ print("string[-1]=",string[-1])
print("string[1:8]=",string[1:8]) #[1,8] 前闭后开
print("string[1:-3]=",string[1:-3]) #[1,-3] 前闭后开
#[::2]
print(string[::2])
print(string[::2])
#前面默认位置为0.::后面的2表示步长
#[1::2]
print(string[1::2])
print(string[1::2])
#前面默认位置为1,::后面的2表示步长
#[::-1]
print(sting[::-1])
print(sting[::-1]) #前面默认位置为-1,::后面的-1表示步长
#[2:10:3]
print(sting[2:10:3]) #(2,10)前闭后开的范围,3表示步长
#[10::-3]
print(string[10::-2])
#[-10:-4:6]
print(string[-10:-4:6])
print(string[-10:-4:6])
"""
#题目:截取"llo w"
string
=
"Hello world!"
print
(
string
[
2
:
7
])
print
(
string
[
2
:
-
4
])
print
(
string
[
-
9
:
7
])
print
(
string
[
-
9
:
-
4
])
print
(
string
[
2
:
-
5
])
print
(
string
[
-
10
:
7
])
print
(
string
[
-
10
:
-
5
])
print
(
"string[2:7]="
,
string
[
2
:
7
])
print
(
"string[2:-5]="
,
string
[
2
:
-
5
])
print
(
"string[-10:7]="
,
string
[
-
10
:
7
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment