Overview
Cut out part of a string or list with [start:stop], and reverse it with [::-1].
- [start:stop] stops before stop
- Leaving out start or stop
- [::-1] reverses
Short Course
text[start:stop] takes the part from start up to, but not
including, stop. Leave one out to go to the edge.
word = "Python"
print(word[0:2]) # Py
print(word[:3]) # Pyt
print(word[-2:]) # on
print(word[::-1]) # nohtyP
Task
Write preview(text, n) that returns the first n characters followed by
… when the text is longer than n, or the text unchanged otherwise.
Test Suites
Pending
Stdout