slicing.py 205 Bytes
Newer Older
nishanth's avatar
nishanth committed
1 2 3 4 5 6 7 8 9 10 11 12 13
pyString = 'Python'

# contains indices (0, 1, 2)
# i.e. P, y and t
sObject = slice(3)

print(pyString[sObject])

# contains indices (1, 3)
# i.e. y and h
sObject = slice(1, 5, 2)

print(pyString[sObject])