Skip to content

Bp #1130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Bp #1130

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Eigth challenge completed
  • Loading branch information
BaoPham92 committed Feb 11, 2020
commit cf76834b64cfd7762a5f3b1f48c66b29054943bb
17 changes: 10 additions & 7 deletions src/07_slices.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,32 @@
Use Python's slice syntax to achieve the following:
"""

# * SOLUTIONS BELOW:
# * OPEN INTERPRETER && RUN: python3 07_slices.py

a = [2, 4, 1, 7, 9, 6]

# Output the second element: 4:
print()
print(a[1])

# Output the second-to-last element: 9
print()
print(a[-2])

# Output the last three elements in the array: [7, 9, 6]
print()
print(a[-3:])

# Output the two middle elements in the array: [1, 7]
print()
print(a[2:4])

# Output every element except the first one: [4, 1, 7, 9, 6]
print()
print(a[-5::1])

# Output every element except the last one: [2, 4, 1, 7, 9]
print()
print(a[0:-1])

# For string s...

s = "Hello, world!"

# Output just the 8th-12th characters: "world"
print()
print(s[-6:-1])