In Python a string is immutable. I find the function string.join() could add the value to a string but it seems the following doesn't work.
#coding: utf-8
if __name__ == "__main__":
str = "A fox has jumped into the river"
tmp = ""
for i in str:
tmp = tmp.join(i)
print tmp
I expect the output should be "A fox has jumped into the river", but it output the "r" why?
Is there any similar methods which is something like string.append()?
i- on of each symbol in that string. And so when loop comes to last iteration -ibecomes last symbol of the string -'r'.join()is the method of string object, which joins sequence elements, provided as argument, separated by object to which this method bounded. In your case you joining sequence (string) with one element'r'with separator''- and you getting result -'r'''.join([str1, str2])