""" Purpose: demonstrate basic usage of string [] operator to look at individual characters. """ # Get three indices of user interest reply = input( "Enter three indices: " ) i1, i2, i3 = reply.split() i1 = int ( i1 ) i2 = int ( i2 ) i3 = int ( i3 ) # Initialize target string s = "chrestomathics" # [] are like backwards find() we start with an index and get a character/sequence # Use the indices to pick off single characters from s c1 = s[ i1 ] # Grab character at index i1 in s c2 = s[ i2 ] # Grab character at index i2 in s c3 = s[ i3 ] # Grab character at index i3 in s # string_name[ index ] where index is an integer will hand back the character at that index in string_name # we'll grab more characters next time! it's called slicing # we don't modify the string s at all, we just grab that letter and store it in c1,c2,c3 # Use the characters to make a new string t = c1 + c2 + c3 # string concatenation - puts all the strings together without spaces # Print the result print() print( t )