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

Contenu du cours

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

Tâche

Swipe to start coding

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

Height: 170 cm

Weight: 70 kg

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 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 $.

Tâche

Swipe to start coding

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

Height: 170 cm

Weight: 70 kg

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 8
Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
We're sorry to hear that something went wrong. What happened?
some-alt