Concatenation joins strings end to end. In Python, the + operator combines literal text and variables into a new string. section 2.1.5 section 2.5
Join a word into a phrase
word = 'narwhal' message = 'Ahoy, Captain, a ' + word + ' off the larboard bow!' print(message) # Ahoy, Captain, a narwhal off the larboard bow! section 2.1.5
Choose a construction technique according to the shape of the output:
- Use str.format() with {} placeholders when substituting values by argument order. section 2.1.12
- Use an f-string to place variables directly inside a string template. section 2.1.12
- Use str.join() or + when assembling generated text, such as insults built from selected words. section 9.1.5 section 10.3.1
>>> 'Ahoy, Captain, a ' + word + ' off the larboard bow!' 'Ahoy, Captain, a narwhal off the larboard bow!'
Inspect the REPL expression and its resulting concatenated sentence. section 2.1.5









