""" Purpose: demonstrate the printing of a string of characters """ # get a string reply = input( "Enter text: " ) words = reply.split() # when you split(), you're processing a list. if you have one word, you have a list with # only one element # if you have target = text.split(), you will ALWAYS get a list back. when i just hit enter, words = [], # an empty list print() print( words ) ### print the characters in s, one by one # one by one/ for each -> for loop! # c/ch are common variable names for characters... don't use char as it's a keyword in many other languages # if we loop through words instead of reply, we'll process word by word, not character by character # for loop_variable in sequence : - python will automatically assign the loop_variable to a different item # in the sequence. python handles this assignment for us, thank you python! # the colon is a separator between the loop declaration and the code in the body of the for loop for current_character in reply : # a string is a sequence of characters, so each time we run through # imagine there's an invisible statement here that says current_character = next character in reply # current_character is going to take on the next character in the string s # we'll process character by character only when we're looping through a string, like reply # print out current_character print( "current_character:", current_character ) print( "donezo" ) # for loop is over, no more indentation # print( "one more time" ) we can't start indenting after we unindent # why do we split() in lickety_split and not here? in this, we want to process character by character, which is done by # looping through a string. input() will always hand back a string, so if we want to do word by word we have # to split() that string into a list first # wherever a python statement is legal, any python statement is legal. you can have loops in loops in loops, # this will increase the complexity in ways you can learn about in future CS classes # don't name your loop variable the same thing as your sequence. you can only have 1 thing stored in each # variable, don't overwrite things that you want to keep