Course Content
String Manipulation in Python
String Manipulation in Python
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,
price = 25 print('Price is', str(price) + '$')
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 wrotestr(price) + ' $'
it would outputPrice is 25 $
.
Swipe to show code editor
Given variables height
and weight
. Using concatenation, output the following messages:
Height: 170 cm
Weight: 70 kg
Thanks for your feedback!
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,
price = 25 print('Price is', str(price) + '$')
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 wrotestr(price) + ' $'
it would outputPrice is 25 $
.
Swipe to show code editor
Given variables height
and weight
. Using concatenation, output the following messages:
Height: 170 cm
Weight: 70 kg
Thanks for your feedback!
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,
price = 25 print('Price is', str(price) + '$')
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 wrotestr(price) + ' $'
it would outputPrice is 25 $
.
Swipe to show code editor
Given variables height
and weight
. Using concatenation, output the following messages:
Height: 170 cm
Weight: 70 kg
Thanks for your feedback!
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,
price = 25 print('Price is', str(price) + '$')
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 wrotestr(price) + ' $'
it would outputPrice is 25 $
.
Swipe to show code editor
Given variables height
and weight
. Using concatenation, output the following messages:
Height: 170 cm
Weight: 70 kg