Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 通过迭代检查字符串_Python 3.x_Loops - Fatal编程技术网

Python 3.x 通过迭代检查字符串

Python 3.x 通过迭代检查字符串,python-3.x,loops,Python 3.x,Loops,我输入一个单词。我想检查单词内容是否为字母“a”。 最后使用print() 问题是我不知道在continue 我想要的结果如下: 例1: 苹果 字:a 例2: 家 没有:a 假设您需要使用for循环,而不是只检查str1中的'a',请使用a for else if 'a' in input(): print('word:a') else: print('without:a') 在“继续”之后,无法在循环中运行代码。。。这就是continue语句的要点 if 'a' in inp

我输入一个单词。我想检查单词内容是否为字母“a”。 最后使用
print()

问题是我不知道在
continue

我想要的结果如下:

例1:

苹果

字:a

例2:

没有:a


假设您需要使用for循环,而不是只检查str1中的
'a',请使用a for else

if 'a' in input():
    print('word:a')
else:
    print('without:a')

在“继续”之后,无法在循环中运行代码。。。这就是continue语句的要点
if 'a' in input():
    print('word:a')
else:
    print('without:a')
str1=input()

for i in str1:
    if i=='a'
        print('word:a')
        break
else:
    print('without:a')
print("word:a" if 'a' in input() else "without a")