Course Content
Data Types in Python
Data Types in Python
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').
string1 = "Tell me why you cried," string2 = " and why you lied to me" string = string1 + string2 print(string)
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.
Swipe to show code editor
One more task for you, fill the gaps and follow the algorithm:
- Print
country: Italy
. - Print
country: Ukraine
. - Print
country: Egypt
.
Thanks for your feedback!
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').
string1 = "Tell me why you cried," string2 = " and why you lied to me" string = string1 + string2 print(string)
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.
Swipe to show code editor
One more task for you, fill the gaps and follow the algorithm:
- Print
country: Italy
. - Print
country: Ukraine
. - Print
country: Egypt
.
Thanks for your feedback!