Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Strings Concatenation | Basic Concepts
String Manipulation in Python
course content

Зміст курсу

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

Завдання

Swipe to start coding

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

Height: 170 cm

Weight: 70 kg

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 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 $.

Завдання

Swipe to start coding

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

Height: 170 cm

Weight: 70 kg

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 8
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt