📚
String Concatenation
Joining Strings Together
Concatenation means joining strings end-to-end using the
+first = "Hello" second = "World" greeting = first + " " + second print(greeting) # → Hello World
Important: the
+" "Concatenation vs print() with commas
These produce the same output but work differently:
print("Hello" + " " + "World") # Concatenation — you control spaces print("Hello", "World") # Commas — Python adds spaces for you
You can't concatenate strings with numbers!
age = 25 print("I am " + str(age) + " years old") # Must convert with str() # Or better, use f-strings: print(f"I am {age} years old") # Much cleaner!
💡💡 For complex string building, f-strings (covered in a later lesson) are much cleaner than concatenation. But understanding
is still important!+
main.pySandbox
main.py
Ctrl + Enter