什么是Python 3相当于find()? - 代码日志

什么是Python 3相当于find()?

我正在开发麻省理工学院开放的python课件,但是以下例子很困难:

To get started, we are going to use some built-in Python functions. To use these functions, include the statement
from string import *
at the beginning of your file. This will allow you to use Python string functions. In particular, if you want to find the starting point of the first match of a keyword string key in a target string target you could use thefind function.
Try running on some examples, such as find(“atgacatgcacaagtatgcat”,”atgc”)
Note how it returns the index of the first instance of the key in the target. Also note that if no instance of the key exists in the target, e.g, find(“atgacatgcacaagtatgcat”,”ggcc”) it returns the value -1.

python 2.4(或许)的课程,但我正在Py3中做任务,沿途学习差异。

使用字符串的.find()方法,而不是string.find()。 (这也可以在python 2中工作,可能更为可取)。
http://stackoverflow.com/questions/6644074/what-is-the-python-3-equivalent-of-find

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:什么是Python 3相当于find()?