Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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 python3 shell(3.81版)SyntaxError中的简单循环_Python 3.x - Fatal编程技术网

Python 3.x python3 shell(3.81版)SyntaxError中的简单循环

Python 3.x python3 shell(3.81版)SyntaxError中的简单循环,python-3.x,Python 3.x,我无法理解为何在python3 shell中不起作用: >>> import random >>> arr = [[]] >>> for i in range(3): ... a = random(sample(range(1,50),6) ... arr[0].append(a) File "<stdin>", line 3 arr[0].append(a) ^ SyntaxError: in

我无法理解为何在python3 shell中不起作用:

>>> import random
>>> arr = [[]]
>>> for i in range(3):
...     a = random(sample(range(1,50),6)
...     arr[0].append(a)
  File "<stdin>", line 3
    arr[0].append(a)
    ^
SyntaxError: invalid syntax
>>> 
这些线是不一样的,我甚至投入了额外的努力,以显示它们之间的差异,以防它不是立即显而易见:-)

第一行带有不平衡的括号,导致后面的一行出现错误,因为它检测到您没有正确终止语句。

a=random(sample(range(1,50),6)
这一行与python文件中的一行不同
    1 import random
    2 
    3 arr = [[]]
    4 
    5 for i in range(14):
    6     a = random.sample(range(1, 50), 6)
    7     arr[0].append(a)
    8 print(arr)
#         v
a = random(sample(range(1,50),6)
a = random.sample(range(1,50),6)
#         ^