gpt4 book ai didi

python - => 在谷歌 Python 示例中

转载 作者:太空宇宙 更新时间:2023-11-03 13:17:34 25 4
gpt4 key购买 nike

所以我是 Python 新手,正在尝试通过 Google Python 在线类(class)学习 [ https://developers.google.com/edu/python/regular-expressions]

我正在运行 Python 2.7.5,当我尝试这个例子时,=> 有问题。

我尝试在谷歌上搜索解释,但一无所获。任何帮助将不胜感激。

错误信息如下。

sandbox$./re-test.py 
File "./re-test.py", line 8
match = re.search(r'iii', 'piiig') => found, match.group() == "iii"
^

程序代码是:

#!/usr/bin/python

import re

## Search for pattern 'iii' in string 'piiig'.
## All of the pattern must match, but it may appear anywhere.
## On success, match.group() is matched text.
match = re.search(r'iii', 'piiig') => found, match.group() == "iii"
match = re.search(r'igs', 'piiig') => not found, match == None

## . = any char but \n
match = re.search(r'..g', 'piiig') => found, match.group() == "iig"

## \d = digit char, \w = word char
match = re.search(r'\d\d\d', 'p123g') => found, match.group() == "123"
match = re.search(r'\w\w\w', '@@abcd!!') => found, match.group() == "abc"

最佳答案

作者使用=>来描述结果;它不是 Python 语法的一部分。

考虑写成下面这样,其意图可能更清楚:

match = re.search(r'iii', 'piiig')  #=> found, match.group() == "iii"

关于python - => 在谷歌 Python 示例中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24420379/

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