Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Merge Strings | Strings
Data Types in Python
Section 3. Chapter 13
single

single

Merge Strings

Swipe to show menu

It is valuable to understand how to merge strings. In Python, this is achieved effortlessly by using the + operator. While this may seem obvious, I will provide a detailed explanation as customary. Consider the following example (a well-known string from The Beatles' song 'Tell Me Why').

12345
string1 = "Tell me why you cried," string2 = " and why you lied to me" string = string1 + string2 print(string)
Note
Note

This process is referred to as concatenation, and it functions much like glue, essentially combining them together. If you want strings to appear more readable, include spaces manually — concatenation does not insert them automatically.

Task

Swipe to start coding

One more task for you:

  1. Create a variable output1 that combines string1 and string2 to form the phrase "country: Italy".
  2. Create a variable output2 that combines string1 and string3 to form the phrase "country: Ukraine".
  3. Create a variable output3 that combines string1 and string4 to form the phrase "country: Egypt".

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 13
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt