-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path056-slice.py
More file actions
23 lines (19 loc) · 881 Bytes
/
056-slice.py
File metadata and controls
23 lines (19 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
Return a slice object
---------------------
Params: start (int) [optional] which position to start slicing
default: 0
end (int) [optional] which position to end slicing
step (int) [optional] step of slicing
default: 1
Return: (obj) slice object
"""
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
slice_1 = slice(7)
print('Original letters: {}\nSlice: {}\n'.format(letters, letters[slice_1]))
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
slice_2 = slice(1,7)
print('Original letters: {}\nSlice: {}\n'.format(letters, letters[slice_2]))
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
slice_3 = slice(1,7,2)
print('Original letters: {}\nSlice: {}'.format(letters, letters[slice_3]))