我在Python中有很多字符串。
示例:
url="CVE-2020-7211,https://gitlab.freedesktop.org/slirp/libslirp/commit/14ec36e107a8c9af7d0a80c3571fe39b291ff1d4"
url="CVE-2020-5204,https://github.com/troglobit/uftpd/commit/0fb2c031ce0ace07cc19cd2cb2143c4b5a63c9dd"
url="CVE-2020-7039,https://gitlab.freedesktop.org/slirp/libslirp/commit/2655fffed7a9e765bcb4701dd876e9dab975f289"
url="CVE-2020-7039,https://gitlab.freedesktop.org/slirp/libslirp/commit/82ebe9c370a0e2970fb5695aa19aa5214a6a1c80"
我需要选择包含https://github.com/
和/commit/
的那些>
我的代码:
if ("https://github.com/" and "/commit/") in url: print("OK") else: print("not okay")
此代码与上面示例中的所有4种情况匹配。我需要它只匹配第二个URL。
我该怎么办?
我在Python中有很多字符串。示例:url =“ CVE-2020-7211,https://gitlab.freedesktop.org/slirp/libslirp/commit/14ec36e107a8c9af7d0a80c3571fe39b291ff1d4” url =“ CVE-2020-5204,https:// github ....
您不能像这样使用and
,您需要分开声明:
if "https://github.com/" in url and "/commit/" in url:
print("OK")
else:
print("not okay")