-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-find.py
More file actions
41 lines (30 loc) · 931 Bytes
/
string-find.py
File metadata and controls
41 lines (30 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
s = "That I ever did see. Dusty as the handle on the door"
index = s.find("Dusty")
print(index)
s = "That I ever did see. Dusty as the handle on the door"
if "Dusty" in s:
print("query found")
"""
Exercise
Try the exercises below
1.Find out if string find is case sensitive
2.What if a query string appers twice in the string?
3.Write a program that asks console input and searches for a query.
"""
#Find out if string find is case sensitive
s = "THAT I EVER DID SEE. DUSTY AS THE HANDLE ON THE DOOR"
if "Dusty" in s:
print("query found")
else:
print("query not found")
#What if a query string appers twice in the string?
s = "Hello world world"
index = s.find("world")
print(index)
#Write a program that asks console input and searches for a query.
s = input("请输入字符串:")
p = input("请输入要查找的字符串:")
if p in s:
print("查找成功")
else:
print("查找失败")