I would like to read some characters from a string and put it into other string (Like we do in C).
So my code is like below
import string
import re
str = "Hello World"
j = 0
srr = ""
for i in str:
srr[j] = i #'str' object does not support item assignment
j = j + 1
print (srr)
In C the code may be
i = j = 0;
while(str[i] != '\0')
{
srr[j++] = str [i++];
}
How can I implement the same in Python?
str
as a variable here, you will be unable to do string conversions withstr(var_that_is_not_a_string)
or type comparisions such astype(var_with_unknown_type) == str
. - Joel CornettTypeError: 'str' object does not support item assignment
. - Friedrich