Skip to content

Instantly share code, notes, and snippets.

@raeq
raeq / slicing.py
Created August 31, 2020 12:14
Mix and Match
hello: str = 'Hello World!'
assert hello[-2:5:-1] == 'dlroW'
@raeq
raeq / slicing.py
Created August 31, 2020 12:09
Working backwards.
hello: str = 'Hello World!'
assert hello[10:5:-1] == 'dlroW'
hello: str = 'Hello World!'
assert hello[-6:-1] == 'World'
@raeq
raeq / slicing.py
Created August 31, 2020 11:54
Ungreedy slice.
hello: str = 'Hello World!'
assert hello[:5] == 'Hello'
@raeq
raeq / slicing.py
Created August 31, 2020 11:50
To the end, Slice!
hello: str = 'Hello World!'
assert hello[6:] == 'World!'
@raeq
raeq / slicing.py
Created August 31, 2020 11:44
A slice
hello: str = 'Hello World!'
print(hello[3:8])
assert hello[3:8] == 'lo Wo'
@raeq
raeq / slicing.py
Created August 31, 2020 11:20
Enumeration of a string.
hello: str = 'Hello World!'
print (list(enumerate(hello)))
hello: str = 'Hello World!'
assert hello[-6] == 'W'
@raeq
raeq / slicing.py
Created August 31, 2020 11:13
Accessing an index.
hello: str = 'Hello World!'
assert hello[6] == 'W'
@raeq
raeq / slicing.py
Created August 31, 2020 11:11
Length of a string
hello: str = 'Hello World!'
assert len(hello) == 12