Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Strings Concatenation | Basic Concepts
String Manipulation in Python
course content

Kursinhalt

String Manipulation in Python

String Manipulation in Python

1. Basic Concepts
2. String Methods
3. Strings Formatting

book
Strings Concatenation

What if we need to connect two strings? Like, we have a price as a number in price variable, and we want to make it representatively, i.e. we want to show the price in format n $. This problem can be solved by concatenation.

Concatenation is joining two strings, which can be done in Python by using a simple + operator. It will join the string on the left side of the operator to the string on the right side. For example,

12
price = 25 print('Price is', str(price) + '$')
copy

As we can see, + operator added the '$' sign to the price converted into a string.

Note

All the space characters are considered by + operator. For example, if in the example above we wrote str(price) + ' $' it would output Price is 25 $.

Aufgabe

Swipe to start coding

Given variables height and weight. Using concatenation, output the following messages:

Height: 170 cm

Weight: 70 kg

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 8
toggle bottom row

book
Strings Concatenation

What if we need to connect two strings? Like, we have a price as a number in price variable, and we want to make it representatively, i.e. we want to show the price in format n $. This problem can be solved by concatenation.

Concatenation is joining two strings, which can be done in Python by using a simple + operator. It will join the string on the left side of the operator to the string on the right side. For example,

12
price = 25 print('Price is', str(price) + '$')
copy

As we can see, + operator added the '$' sign to the price converted into a string.

Note

All the space characters are considered by + operator. For example, if in the example above we wrote str(price) + ' $' it would output Price is 25 $.

Aufgabe

Swipe to start coding

Given variables height and weight. Using concatenation, output the following messages:

Height: 170 cm

Weight: 70 kg

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 8
Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
We're sorry to hear that something went wrong. What happened?
some-alt