+91 81900 98289

Concatenate Strings

This Concatenate Strings lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.

The + operator joins strings. A number has to become text with str before it can be joined this way.

join is the better tool when many pieces share one separator.

Example 1: Start here

An f-string is clearer when values sit inside a sentence.

city = "Chennai" # text year = 2026 # a whole number print(city + " " + str(year)) # plus joins text; use str() for a number print(" | ".join(["Python", "SQL"])) # join the pieces into one text

Example 2: Join with plus

Plus joins text. A space is its own string if you want a gap.

print("Python" + " " + "tutorial") # plus joins text; use str() for a number

Example 3: Join a list

join is the tidy way to combine many pieces.

words = ["Python", "SQL", "Git"] # a list; the values stay in this order print(", ".join(words)) # join the pieces into one text

Example 4: Repeat text

A string times a number repeats the text.

print("Ha" * 3) # print writes this; the quotes are not shown
An f-string is clearer when values sit inside a sentence.
Call Now 81900 98289