스크립트
[코딩테스트 입문] 특정 문자 제거하기
변군이글루
2022. 11. 18. 15:46
반응형
특정 문자 제거하기
1안) solution.py
import re
def solution(my_string, letter):
answer = ''
answer = re.sub(letter, "", my_string)
return answer
2안) solution.py
def solution(my_string, letter):
answer = ''
answer = my_string.replace(letter, '')
return answer
출처 - 프로그래머스(코딩테스트 연습) : https://school.programmers.co.kr/learn/courses/30/lessons/120826
파이썬 정규식 re
import re
#Replace all white-space characters with the digit "9":
txt = "The rain in Spain"
x = re.sub("\s", "9", txt)
print(x)
The9rain9in9Spain
파이썬 문자열 replace() 메서드
txt = "I like bananas"
x = txt.replace("bananas", "apples")
print(x)
I like apples
참고URL
- w3schools : https://www.w3schools.com/python/python_regex.asp
- w3schools : https://www.w3schools.com/python/ref_string_replace.asp
728x90
반응형