问题本身在这里解释:s
是要搜索的字符串,target是要查找的子字符串。打印目标开始处的每个索引。你知道吗
'''Exercise to complete printLocations as described below.
Create File locations.py.'''
def printLocations(s, target):
'''
s is a string to search through, and target is the substring to look for.
Print each index where the target starts.
For example:
>>> printLocations('Here, there, everywherel', 'ere')
1
8
20
'''
repetitions = s.count(target)
# ?? add initialization
for i in range(repetitions):
# ?? add loop body lines
def main():
phrase = 'Here, there, everywhere!'
print('Phrasez', phrase)
for target in ['ere', 'er', 'e', 'eh', 'zx']:
print('finding:', target)
printLocations(phrase, target)
print('All done!')
main()
演示:
祝你好运向你的老师解释。。。。你也可以这样做:
相关问题 更多 >
编程相关推荐