-2

我正在制作一个不同的程序,在这种情况下,如果变量中有任何来自变量A的字符串,B它应该打印正常

A = "hello", "nice"

B = "this dress is very nice"
if A in B : 
    print("ok")

我收到错误 -

[Done] exited with code=1 in 0.183 seconds
4

1 回答 1

2

关于您的要求

如果变量A中的变量有任何字符串B

那应该是:如果其中有一部分A等于B,则对应的代码是

A = "hello", "nice"
B = "nice"
if B in A:
    print("ok")

如果您想要一个可能的部分匹配:一个单词A包含在B,请使用:

A = "hello", "nic"
B = "nice"
if any(word in B for word in A):
    print("ok")
于 2021-11-15T17:42:05.267 回答