함수 endsWith()

1 Python[ | ]

Python
CPU
0.0s
MEM
8M
0.0s
Copy
print('world'.endswith('world'));         # True
print('hello world'.endswith('world'));   # True
print( 'hello worl'.endswith('hello') );  # False
True
True
False
Python
CPU
0.0s
MEM
8M
0.0s
Copy
# handmade for fun
import re
def my_endswith(needle, haystack):
    return not not re.match(r'.*'+needle+'$', haystack)

print(my_endswith('world', 'world'));       # True
print(my_endswith('world', 'hello world')); # True
print(my_endswith('world', 'hello worl'));  # False
True
True
False

2 같이 보기[ | ]