gpt4 book ai didi

python - 什么是 Python 3 中的 find()?

转载 作者:IT老高 更新时间:2023-10-28 20:31:49 24 4
gpt4 key购买 nike

我正在为 Python 编写 MIT 开放课件,但对以下示例感到困难:

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(左右)的类(class),但我正在尝试在 Py3 中完成作业.. 学习沿途的差异。

最佳答案

使用字符串的.find() 方法,而不是string.find()。 (这在 python 2 中也有效,并且可能更可取)。

关于python - 什么是 Python 3 中的 find()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6644074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com