티스토리 뷰

Tip and Error/Python

문자열(' ')은 변경 할 수 없다.

geonwoopaeng@gmail.com 2020. 9. 6. 16:59

문자열은 index로 확인을 할 수 있지만 

변경은 할 수 없습니다.

 

그래서 

list로 바꾼 후 변경을 해야 합니다.

 

word = input() #입력 asdf -> 출력 'asdf' 
word[2] = ')' # 변경이 불가능 하다 

word = list(word)
word[2] = ')' # 변경이 가능하다

 

error

'str' object does not support item assignment

( 'str' 객체가 항목 할당을 support 하지 않습니다.) 

반응형

'Tip and Error > Python' 카테고리의 다른 글

defaultdict - collections 모듈  (0) 2020.10.14
reverse() & reversed() & [::-1]  (0) 2020.10.02
DP 풀 때  (0) 2020.08.27
deque (collections 모듈)  (0) 2020.08.27
시간 측정  (0) 2020.08.24
공지사항
최근에 올라온 글