python 判断变量是否在文本中方法
时间: 2023-04-09 11:02:21 浏览: 59
可以使用 in 关键字来判断一个变量是否在文本中,例如:
text = "Hello world"
if "world" in text:
print("变量在文本中")
else:
print("变量不在文本中")
相关问题
python 判断变量是否在文本中方法,返回布尔值
可以使用 in 关键字来判断变量是否在文本中,返回布尔值。例如:
text = "Hello, world!"
variable = "world"
if variable in text:
print("Variable is in text")
else:
print("Variable is not in text")
输出结果为:Variable is in text
python 自带的判断变量是否在文本中方法
可以使用 in 关键字来判断一个变量是否在文本中,例如:
text = "Hello, world!"
if "world" in text:
print("world is in the text")
else:
print("world is not in the text")