Python 정규 표현식
Maria Eugenia Inzaugarat
Data scientist

my_string = "Where's Waldo?"
my_string.find("Waldo")
8
my_string.find("Wenda")
-1
my_string = "Where's Waldo?"
my_string.find("Waldo", 0, 6)
-1
.find()와 유사하게, 대상 문자열에서 지정한 부분 문자열을 검색합니다.
my_string = "Where's Waldo?"
my_string.index("Waldo")
8
my_string.index("Wenda")
File "<stdin>", line 1, in <module>
ValueError: substring not found
.find()와 유사하게, 대상 문자열에서 지정한 부분 문자열을 검색합니다.
my_string = "Where's Waldo?"
try:
my_string.index("Wenda")
except ValueError:
print("Not found")
"Not found"

my_string = "How many fruits do you have in your fruit basket?"
my_string.count("fruit")
2
my_string.count("fruit", 0, 16)
1

my_string = "The red house is between the blue house and the old house"
print(my_string.replace("house", "car"))
The red car is between the blue car and the old car
print(my_string.replace("house", "car", 2))
The red car is between the blue car and the old house
문자열 조작:
Python 정규 표현식