Solution Review: String Transformation
This lesson will give a detailed review of how to update a string.
We'll cover the following
Solution: Use len()
and concatenation(+)
Operation
-
Use
len(str)
to calculate the length of stringstr
-
Concatenate value at a certain position in the string using the concatenation operation
Given a string 'str'
, use the following piece of code to transform the string
str = str[:position] + character_to_insert + str[position:]
The character needs to be inserted where the position is in the code.
Have a look at the following illustration to get an insight on how to update the length of a string using concatenation operation.
Get hands-on with 1400+ tech skills courses.