python's string query statistics

Find the position of characters in the query string, the first character in line with the position, find there is no return -1, index will complain

a="i love chian"
fnd=a.find('i')
idx=a.index("n")
print("字符串a中字符i的位置为:%d"%fnd)
print("字符串a中字符n的位置为:%d"%idx)

Here Insert Picture Description
Determining whether a character string in the string b, returns a Boolean value

a='chian'
b='i love chian'
s= a in b
print(s)

Here Insert Picture Description
The number of characters within a string of statistics

a="i love chian"
cnt=a.count('i')
print("字符串a中字符i的个数为:%d"%cnt)

Here Insert Picture Description
Analyzing the letter string is not repeated
https://blog.csdn.net/GrofChen/article/details/92406250

Guess you like

Origin blog.csdn.net/GrofChen/article/details/92397390