liveBook · Manning

Concatenation

As explained in Get Programming: Learn to code with Python

Concatenation is the operation of joining ordered sequences end to end to form a single sequence.

Concatenation joins two strings with +, preserving their order and creating a new string. Add any spaces or separators you want included: "one" + "two" produces "onetwo". section 8.2

Use concatenation to assemble text from smaller pieces, such as combining report sections or name fragments. The + operator can also join tuples, as when adding a newly found word to a tuple of valid words. section 8.2 section 19.2

Listing 12.4. Combining the names
newname1_first = lefthalf_name1_first.capitalize() +  \              #1
righthalf_name2_first.lower()                                        #2
newname1_last = lefthalf_name1_last.capitalize() +  \
righthalf_name2_last.lower()

newname2_first = lefthalf_name2_first.capitalize() +  \
righthalf_name1_first.lower()
newname2_last = lefthalf_name2_last.capitalize() +  \
righthalf_name1_last.lower()

print("All done! Here are two possibilities, pick the one you like best!")
print(newname1_first, newname1_last)                                 #3
print(newname2_first, newname2_last)                                 #3

This name-mashup code joins capitalized and lowercase name halves to create new names. section 12.4

How Get Programming: Learn to code with Python covers it

How deep it goes
Defines string concatenation with +, explains order and new-string results, and demonstrates tuple concatenation in code.
Examples
Uses report sections, short string expressions, mashed-up names, and valid-word tuples.
What it assumes
Uses string values and variables in examples, then introduces string addition through direct demonstrations.
What you can do after
Apply concatenation with + to assemble strings or extend tuples in small programs.
How it connects
Connects to strings, tuples, string manipulation, capitalization, and printing.

Also explained in

Compare how 10 books explain concatenation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.