# Additions.py Copyright (c) 2006 Kari Laitinen # http://www.naturalprogramming.com # 2006-05-28 File created. # 2006-05-30 Last modification. # The corresponding Java program Additions.java demonstrates # how the + operator automatically converts numerical values # to strings and joins the resulting strings to other strings. # In Python, the + operator also works as a concatenation # operator that can concatenate strings, tuples, and lists. # The Python + operator does not, however, automatically # convert numerical values to strings. The standard # built-in function str() can be used to make these conversions. some_integer = 1234 print "xxxx" + str( some_integer ) + "zzzz" print "xxxx" + str( some_integer ) + str( some_integer ) + "zzzz" print "xxxx" + str( some_integer + some_integer ) + "zzzz" print str( some_integer + some_integer ) + "xxxx" + "zzzz" print str( some_integer ) + ( str( some_integer ) + "xxxx" ) + "zzzz" print "xxxx" + "zzzz" + str( some_integer ) + str( some_integer + 1 ) print "xxxx" + "zzzz" + str( some_integer ) + str( some_integer ) + str( 1 )