class Solution:
def strStr(self, haystack: str, needle: str) -> int:
if not needle:return 0
n1 = len(haystack)
n2 = len(needle)
for i in range(n1 - n2 + 1):
if haystack[i:i+n2] == needle:
return i
return -1
列表、字符串、字典、元组都能进行切片操作