Larry Bates wrote:
>> How do I replace a single character in a string at a given position?
You can't. Strings can't be mutated in Python how ever hard you try.
The string type is immutable. (Of course, I suspect you can write a
horrible C extension that would help you cheat. Yuk!)
You need to cre
[EMAIL PROTECTED] wrote:
> Martin Kulas:
>> Are there better (faster) ways to achieve my goal?
>> I have looked through the methods of type ``string''
>> but I have not found any appropriate method or function.
[...]
> A second way is to use a list of strings with len=1. Like this:
idx = 1
>>>
Martin Kulas wrote:
> Hello!
>
> How do I replace a single character in a string at a given position?
>
> From programming languages like C I expect something like that:
>
idx = 1
s1 = "pxthon"
s1[idx] = 'y'
> Traceback (most recent call last):
> File "", line 1, in ?
> TypeErro
Martin Kulas:
> Are there better (faster) ways to achieve my goal?
> I have looked through the methods of type ``string''
> but I have not found any appropriate method or function.
Python strings are immutable, so you can't modify them, so you can't
find methods to change them. I agree that someti
Martin Kulas wrote:
> From programming languages like C I expect something like that:
>
idx = 1
s1 = "pxthon"
s1[idx] = 'y'
> Traceback (most recent call last):
> File "", line 1, in ?
> TypeError: object does not support item assignment
>
> It does not work :-(
Yes, Python str
Hello!
How do I replace a single character in a string at a given position?
>From programming languages like C I expect something like that:
>>> idx = 1
>>> s1 = "pxthon"
>>> s1[idx] = 'y'
Traceback (most recent call last):
File "", line 1, in ?
TypeError: object does not support item assignme