Computer Studies‎ > ‎Python‎ > ‎Python Tutorial‎ > ‎

Concatenation

By separating items with a comma (",") in a print statement, you can print more than one item on the same line. The following example...

print ("Nice""picture!")

...prints "Nice picture!" on the screen. Note that when printed in this manner (using a comma), a space is inserted between the two printed objects. In the truest sense, using a comma to join two printed objects is not concatenation, but this following example is:

print ("Nice" + "picture")

If you run this second example you will note that the output does not include a space between the two objects. This is true concatenation, i.e., joining of two strings end-to-end.

Assignment

Add a line to 003.py that prints your last name after your first name using a comma. Be sure it prints on the same line. 

Save as "004.py".

Assignment

As in the assignment above, print your first and last names, but this time print them using a single print statement and the "+" operator. What did you have to do to include a space between your first name and last name?

Save as "004a.py".
Comments