haystack = "hello"
needle = ""
if needle not in haystack:
print(-1)
for i in range(len(haystack)):
if haystack[i] == needle[0]:
print(i)
break
haystack = "hello"
needle = ""
if needle not in haystack or needle == "":
print(-1)
for i in range(len(haystack)):
if haystack[i] == needle[0]:
print(i)
break
haystack = "hello"
needle = ""
if needle not in haystack:
print(-1)
if needle == "":
print(-1)
else:
for i in range(len(haystack)):
if haystack[i] == needle[0]:
print(i)
break
haystack = "hello"
needle = ""
if needle not in haystack:
print(-1)
if needle == "":
print(0)
else:
for i in range(len(haystack)):
if haystack[i] == needle[0]:
print(i)
break
注意最初提到的问题。