Replace at Index
You can replace a specific character in a string by creating a new string that consists of all characters up to some index, the new character than you want to insert, and then the remainder of the original string. Create the function replace_at_index() that accepts a string, an index, and a character as inputs and returns a string with the character at the index replaced with the replacement string.
>>> replace_at_index('dad',0, 'b')
'bad'
>>> replace_at_index('add',2,'s')
'ads'
>>> replace_at_index('tap',1,'o')
'top'
Results | ||||||||||||||||
|
'Python > 왕초보를 위한 파이썬' 카테고리의 다른 글
7.5. 특별한 메서드들 (0) | 2012.04.12 |
---|---|
Python 문자열 (0) | 2012.04.10 |
Python 실습_After Index (0) | 2012.04.10 |
Python 실습_Character Replacement (0) | 2012.04.10 |
Python 실습_Alphabet count (0) | 2012.04.10 |
댓글