Python Change a str with index

사용 버전: Python 3.7.9

파이썬 Change a str with index를 알아보겠습니다.


파이썬에서 str 타입을 인덱스를 써서 변경하려고 하면 다음과 같은 오류가 납니다.





TypeError: 'str' object does not support item assignment




즉, str에는 값을 재정의 할 수 없다는 뜻입니다.




이때는 list롤 사용합니다.

list로 만든 다음에 다시 합쳐주는 과정을 거쳐주면 됩니다.


3 번째 줄에서 list로 만들어 줍니다.

5 번째 줄에서 인덱스로 값을 변경해줍니다.

7 번째 줄에서 ''.join()을 사용해서 전부 합쳐줍니다.






끝.


카테고리: Python

댓글

이 블로그의 인기 게시물

Python urllib.parse.quote()

KiCad 시작하기 4 (기존 회로도 수정 및 추가)

Android Compose Coil library

KiCad 시작하기 1 (회로도 만들기)

Android Notification with Full Screen

iOS Swift callAsFunction

Forensics .pyc 파일 .py로 복구하기

iOS Error Undefined symbol Testing.Trait

Android Custom IME(Input method editor) 만들기

Android Compose automation for getting localized images to use on Play Store app image