''' Purpose: demonstrate the end optional parameter for print() ''' # standard printing -- each print requests ends with the printing of a # new line character print( "Wa-Hoo-Wa" ) print( "Rah-Rah-Rah" ) print() # printing with optional `end=` argument print( "Wa-Hoo-Wa", end="!!!" ) # print ends with explicit "!!!" print( "Rah-Rah-Rah" ) # print ends with implicit "\n" print() # Usually in a print statement # everything is printed in a new line. # what end="..." does is it takes the # ... and uses that to separate # new print statements. # So basically it takes one print # statement and puts that ending # and the next print statement # starts from that ending # So we will see Wa-Hoo-wa!!!Rah-Rah-Rar # because the next print statement # picks up where the last one # left off. This is useful when # you wanna print multiple # things on the same line or at a # particular string/character. print( "Wa-Hoo-Wa", end=" !!! " ) # print ends with explicit " !!! " print( "Rah-Rah-Rah" ) # print ends with implicit "\n" print() for ch in "tattarrattat" : print( ch, end="-" ) # print ends with explicit "-" #end= is basically really # useful for printing stuff out # on the same line or for printing # in a certain structural way # print("CS", end="") # print("Professor Cohoon") # Console looks like this: # CSProfessorCohoon print() # print with implicit "\n" happens print() # after the loop for ch in "saippuakivikauppias" : print( ch, end="" ) # print ends with explicit "", so each # Do you see how it doesn't # print each new print # statement on a new line? # Normally, two print statements # will print out things line after line. # If we put end="..." it'll just # print out the first thing # and then whatever is in the end= # and then print the next line # on the same line following the # end=... # printing in the loop is right after # previous printing print() # print with implicit "\n" happens print() # after the loop