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

Kursinnhold

Data Types in Python

Data Types in Python

1. Getting Familiar With Numbers in Python
2. Mastering Boolean Logic in Python
3. Python String Manipulation
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.

Oppgave

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".

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 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.

Oppgave

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".

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 13
Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Vi beklager at noe gikk galt. Hva skjedde?
some-alt