Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.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中的运算符充当比较运算符,但在for循环中使用时,它充当assogment运算符?_Python_Python 3.x_Python 3.7 - Fatal编程技术网

为什么';在';python中的运算符充当比较运算符,但在for循环中使用时,它充当assogment运算符?

为什么';在';python中的运算符充当比较运算符,但在for循环中使用时,它充当assogment运算符?,python,python-3.x,python-3.7,Python,Python 3.x,Python 3.7,在第一种情况下,中的用于检查它是否包含在第二个字符串中,而中的第二个是迭代字符串的for循环的一部分。因为这就是语言的定义方式。在后一种情况下,中的不是运算符,而是for语句的一部分。这只是同一个英语单词的两种不同用法。这不是赋值,而是对字符串的迭代。作业在哪里?这能回答你的问题吗? 'he' in 'hello' >>>True for i in 'hello': print(i,end = ' ') >>>'h' 'e' 'l' 'l' 'o'

在第一种情况下,中的
用于检查它是否包含在第二个字符串中,而
中的第二个
是迭代字符串的
for
循环的一部分。

因为这就是语言的定义方式。在后一种情况下,
中的
不是运算符,而是
for
语句的一部分。这只是同一个英语单词的两种不同用法。这不是赋值,而是对字符串的迭代。作业在哪里?这能回答你的问题吗?
'he' in 'hello'
>>>True


for i in 'hello':
  print(i,end = ' ')
>>>'h' 'e' 'l' 'l' 'o'