Python has powerful built-in capabilities for string manipulation. That’s why web companies like Google love Python—it’s a perfect fit for the text-based web.
This guide shows you how to use string concatenation operators using multiple forms of education:
- Text
- Puzzle
- Video
- Exercise
Ready to learn string concatenation? Let’s get started!
A Textual Introduction to String Concatenation in Python
There are two basic string manipulation operators.
- The
'+'
operator concatenates two strings. - The
'*'
operator concatenates a string to itself repeatedly.
Those two operators are exemplified in the following example:
>>> 'hello ' + 'world' 'hello world' >>> 'hello ' * 3 'hello hello hello '
The standard arithmetic rules apply to these operators: multiplication first, then addition.
>>> 'hello ' + 'world' * 3 'hello worldworldworld'
Attention: Python’s string type is immutable—meaning that you cannot change an existing string. Instead, Python creates a new string as the result of the string concatenation operators *
and +
.
As a Python professional, you will find yourself using these operators on a daily basis.
๐ Note: Both operands of the string concatenation operation x + y
need to be strings. If you try to append a Boolean to a String, for example, first convert the Boolean to a string.
Can You Solve This String Concatenation Python Puzzle?
print(3 * 'un' + 'ium')
What is the output of this code snippet?
You can evaluate whether you’ve solved the puzzle correctly, and test your coding skills on our Finxter.com puzzle app: Test your skills now!
Watch the Video About String Concatenation
I found this excellent video on YouTube:
Polish Your Skills With This Interactive Shell Exercise About String Concatenation
Here’s a Python exercise. You have given two variables A
and B
with some string content. Create a short and concise Python statement based on string concatenation to generate the desired output:
Scroll down to see the solution…
Where to Go From Here?
Enough theory. Letโs get some practice!
Coders get paid six figures and more because they can solve problems more effectively using machine intelligence and automation.
To become more successful in coding, solve more real problems for real people. Thatโs how you polish the skills you really need in practice. After all, whatโs the use of learning theory that nobody ever needs?
You build high-value coding skills by working on practical coding projects!
Do you want to stop learning with toy projects and focus on practical code projects that earn you money and solve real problems for people?
๐ If your answer is YES!, consider becoming a Python freelance developer! Itโs the best way of approaching the task of improving your Python skillsโeven if you are a complete beginner.
If you just want to learn about the freelancing opportunity, feel free to watch my free webinar โHow to Build Your High-Income Skill Pythonโ and learn how I grew my coding business online and how you can, tooโfrom the comfort of your own home.
Solution Exercise
The solution is simple: the string concatenation expression 3*(A+B) generates the desired output!
A = 'old mcdonald had a farm\n' B = 'yia-yia-yo\n' print(3*(A+B)) ''' old mcdonald had a farm yia-yia-yo old mcdonald had a farm yia-yia-yo old mcdonald had a farm yia-yia-yo '''

While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.