我试图返回包含5的所有数字,包括起始值和结束值。我创建了一个包含所有数字的字符串列表。然而,我很困惑我如何获得值并将它们添加到新列表中。 例如,giveMeFive(42,75)将返回列表[45,50,51,52,53,54,55,56, 57,58,59,65,75]返回所有包含5的数字
def giveMeFive():
num1 = int(input("Whats the first number?"))
num2 = int(input("Whats the second number?"))
lst = str(list(range(num1, num2 + 1)))
print(lst.find("5"))
newLst = []
for x in lst:
if(lst(x) == "5"):
#stuck
请分享投入和预期回报值的例子。 – bfontaine
这是许多不同问题的重复。搜索“python in”和“python append list”。 –
可能重复[检查字符串中的特殊字符?](https://stackoverflow.com/questions/9884958/check-special-character-in-string) –