Определение есть ли подстрока в строке s="1234567121" if "1" in s and "9" not in s: print("Есть") else: print("Нет")