Python 搜索字符串并输出列
因此,我试图让某人输入一个字符串,并让python在第一列中搜索该字符串,如果找到,则输出整行Python 搜索字符串并输出列,python,google-sheets,gspread,Python,Google Sheets,Gspread,因此,我试图让某人输入一个字符串,并让python在第一列中搜索该字符串,如果找到,则输出整行 我是怎么做到的?(使用gspread)如果我正确理解了您的问题,以下是代码: line = ("abcd") try: string = input("Please enter a string: ") if string in line: print(line) else: print("You
我是怎么做到的?(使用gspread)如果我正确理解了您的问题,以下是代码:
line = ("abcd")
try:
string = input("Please enter a string: ")
if string in line:
print(line)
else:
print("Your input is not in line.")
except ValueError:
print("An error has occured")
语句中的
检查输入是否在文本中,如果在文本中,则将其打印出来。(您必须更改行以匹配所需内容,并且对于多行使用“text”“”
)。try
和except
语句使程序更加健壮-尤其是当您只能输入数字(整数或浮点数)时。它不会崩溃,因此是一个好习惯。你可以在谷歌上搜索后缀,因为有很多后缀。非常感谢!我会试试这个,如果我遇到问题,我会告诉你的。