기계는 거짓말하지 않는다

Python String 문자 수정(Modify) 본문

Python

Python String 문자 수정(Modify)

KillinTime 2022. 11. 25. 14:07

문자열은 immutable이므로 문자 수정이 불가능하다.

List 변경 후 다시 문자열로 변환하는 방법이 있다.

temp_str = "ABCDEF"
temp_str = list(temp_str)
temp_str[0] = "g"
temp_str[1] = "h"
temp_str = "".join(temp_str)

print(f"Change String: {temp_str} (Type: {type(temp_str)})")

 

Comments