
str_ends_with 함수는 파이썬 3.10 이상에서 사용할 수 있는 함수입니다. 이 함수는 문자열이 특정 문자열로 끝나는지 확인하는 데 사용됩니다.
str_ends_with 함수는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
python
문자열.endswith(끝나는 문자열)
위의 예를 들어보면,
#hostingforum.kr
python
print("hello".endswith("lo")) # True
print("hello".endswith("world")) # False
위의 예에서 "hello"가 "lo"로 끝나므로 True를 출력하고, "hello"가 "world"로 끝나지 않으므로 False를 출력합니다.
str_ends_with 함수는 여러 문자열을 한번에 확인할 수도 있습니다.
#hostingforum.kr
python
print("hello".endswith(("lo", "world"))) # True
print("hello".endswith(("world", "lo"))) # False
위의 예에서 "hello"가 "lo"로 끝나므로 True를 출력하고, "hello"가 "world"로 끝나지 않으므로 False를 출력합니다.
str_ends_with 함수는 파이썬 3.10 이상에서만 사용할 수 있으므로, 파이썬 버전이 3.10 이하인 경우 다른 방법을 사용해야 합니다.
#hostingforum.kr
python
def str_ends_with(s, suffix):
return s.endswith(suffix)
print(str_ends_with("hello", "lo")) # True
print(str_ends_with("hello", "world")) # False
위의 예에서 str_ends_with 함수를 사용하여 "hello"가 "lo"로 끝나는지 확인합니다.
str_ends_with 함수는 파이썬 3.10 이상에서만 사용할 수 있으므로, 파이썬 버전이 3.10 이하인 경우 위의 예를 사용해야 합니다.
2025-07-18 01:47