The string in python behaves similar to list. Then why can't we change value using assignment operator.
Example:
name = 'whatever'
why can't we do assignment like name[0] = 'k'
If we need to make a change like this, how can we do that?
The string in python behaves similar to list. Then why can't we change value using assignment operator.
Example:
name = 'whatever'
why can't we do assignment like name[0] = 'k'
If we need to make a change like this, how can we do that?
you could do something like this:
s = "abcde" # create string
l = list(s) # convert to list
l[2] = "X" # modify character
"".join(l) # join to string again
A string in Python is immutable. You can use something like .replace() or iterate through the string and create a new one.
For example:
name = 'whatever'
name.replace("w", "k")