''' Purpose: expand input processing capabilities by splitting an input string into its component words ''' # get input # introduces the split() function! reply = input( 'What are your three favorite words: ' ) # user input is stored as a string in reply print() # determine individual words w1, w2, and w3 # SPLIT FUNCTION # The split() function is a function for STRINGS. It will give you a list of words separated by spaces in that string. # Ex. # reply = 'I love CS' # reply.split() -> ['I', 'love', 'CS'] # w1, w2, w3 = ['I', 'love', 'CS'] -> multiple variable assignment # w1 gets 'I', w2 gets 'love', w3 gets 'CS' w1, w2, w3 = reply.split() # format is stringvariable.split() # Same as like w1,w2,w3 = 'peace','joy','friends' # reply is the variable that stores the user input # reply.split() is the format that we will use to call .split() on that string! # If reply was changed to a variable named text or something # it would be text.split() # SPLITTING BY SPACES vs. SPLITTING BY OTHER CHARACTERS / SUBSTRINGS # .split() by default will separate the words at the spaces (whitespace) # .split() takes in an optional argument # you can do reply.split('-') to split on a hyphen for example (examples in Modules > str > .split0 # If reply is 'peace joy friends' # w1,w2,w3 = reply.split() # w1,w2,w3 = ['peace','joy','friends'] # w1 is 'peace', w2 is 'joy', w3 is 'friends' # Assigned sequentially! # Everything on the left is assigned sequentially to the corresponding order on the right! # x, y = 1, 2 # x is 1 and y is 2 # display results print( w1 ) print( w2 ) print( w3 )