text = "1-3-2"# 借助字符列表chars = list(text)chars[2], chars[4] = chars[4], chars[2]text = "".join(chars)# text is '1-2-3'print(f"{text = }")# 字符串是不可变的try: text[2] = "2"except TypeError as error: print(f"{error = }")