Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære String Concatenation in Python | Variables and Types in Python
Introduction to Python (dev copy)

bookString Concatenation in Python

Let's dive into concatenation. This process simply joins two strings together. In Python, you can concatenate two strings using the + operator, much like you'd add numbers.

Note

Concatenation won't automatically insert spaces between the strings you're joining.

For instance, you can combine words with an article:

123456
# Article and word article = "The" country = "Netherlands" # Output result of the concatenations print(article + country) print(article + " " + country) # Add blank space between
copy

Note

Keep in mind, you can only concatenate strings with other strings. In other words, you can't directly concatenate a word like 'word' with a number such as 1. To achieve this, first convert the number to a string using the str(1) function, and then concatenate.

question mark

What result will the following code produce?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 11

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Suggested prompts:

Still meg spørsmål om dette emnet

Oppsummer dette kapittelet

Vis eksempler fra virkeligheten

Awesome!

Completion rate improved to 1.64

bookString Concatenation in Python

Sveip for å vise menyen

Let's dive into concatenation. This process simply joins two strings together. In Python, you can concatenate two strings using the + operator, much like you'd add numbers.

Note

Concatenation won't automatically insert spaces between the strings you're joining.

For instance, you can combine words with an article:

123456
# Article and word article = "The" country = "Netherlands" # Output result of the concatenations print(article + country) print(article + " " + country) # Add blank space between
copy

Note

Keep in mind, you can only concatenate strings with other strings. In other words, you can't directly concatenate a word like 'word' with a number such as 1. To achieve this, first convert the number to a string using the str(1) function, and then concatenate.

question mark

What result will the following code produce?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 11
some-alt