''' Purpose: expand input processing capabilities by splitting an input string into its component words ''' # get input reply = input( 'What are your three favorite words: ' ) print() # We are now introducting the .split() function. # We call .split() on a string like this: # If s is a string, you call s.split() to break s into a list # of smaller strings by breaking up the larger string # at its spaces/whitespace by default! # !!!!!! If s is "I love ice cream" # s.split() gives you ['i','love','ice','cream'] # determine individual words w1, w2, and w3 # If we type in three words, we can split it up into three words # and assign each word to three variables. w1, w2, w3 = reply.split() # reply stores the string we want to split! # () are for functions! If you don't use the (), it won't perform the function. # You all will eventually write your own functions that will need the () to work # display results # prints each word on a separate line # It's just printing the variable values! print( w1 ) print( w2 ) print( w3 ) # Why wouldn't just typing 'abc' work? Because Python splits at whitespace. # You need to put spaces so that it can separate at whitespace. # So if I put ' a b c ' # I would stil get a list of ['a','b','c'] BECAUSE IT SPLITS IT AT WHITESPACE # If we ran 'a b c d' then it blows up because we're trying to assign # a list with ['a','b','c','d'] to three variables. Where does the last one go? # It won't. This code blows up. We will know how to fix this in later examples.. # More on lists later! # .split() will split on whitespace by default but you can # give it an argument and split it at a particular character or sequence.