Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Merge Strings | Strings
Data Types in Python
course content

Course Content

Data Types in Python

Data Types in Python

1. Getting Familiar With Numbers in Python
2. True or False?
3. Strings
4. Bring All the Topics Together

book
Merge Strings

In programming, there are no insurmountable obstacles; persistent practice can overcome any challenge. Therefore, let us discuss another essential aspect related to strings.

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)
copy

Note

This process is referred to as "concatenation," and it functions much like glue, essentially combining them together. If we desire strings to appear more legible, it is advisable to include spaces since concatenation does not automatically insert them.

Task
test

Swipe to show code editor

One more task for you, fill the gaps and follow the algorithm:

  1. Print country: Italy.
  2. Print country: Ukraine.
  3. Print country: Egypt.

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
toggle bottom row

book
Merge Strings

In programming, there are no insurmountable obstacles; persistent practice can overcome any challenge. Therefore, let us discuss another essential aspect related to strings.

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)
copy

Note

This process is referred to as "concatenation," and it functions much like glue, essentially combining them together. If we desire strings to appear more legible, it is advisable to include spaces since concatenation does not automatically insert them.

Task
test

Swipe to show code editor

One more task for you, fill the gaps and follow the algorithm:

  1. Print country: Italy.
  2. Print country: Ukraine.
  3. Print country: Egypt.

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
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt