# indexing and slicing of strings from graphics import * def main(): win = GraphWin('Indexing and Slicing') win.setCoords(0,0,10,10) text1 = Text(Point(5,5),"") text1.draw(win) name = 'Jack Richards' name = name.upper() # examples of using an index: # text1.setText(name[0]) # prints J # text1.setText(name[5]) # prints R # text1.setText(name[-1]) # prints S # examples of slicing: # text1.setText(name[0:4]) # prints JACK # text1.setText(name[:4]) # prints JACK # text1.setText(name[5:]) # prints RICHARDS win.getMouse() main()