Python Jupyter笔记本中接收语法错误
我刚刚开始学习python,我收到下面的错误,我不确定为什么。请帮个忙Python Jupyter笔记本中接收语法错误,python,Python,我刚刚开始学习python,我收到下面的错误,我不确定为什么。请帮个忙 # understanding how lists are stored a = [5, 10] b = a print( "a: {}\t b: {}".format(a, b)) print( "Location a[0]: {}\t Location b[0]: {}".format( id(a[0], id(b[0]))) a[0] = 20 # re
# understanding how lists are stored
a = [5, 10]
b = a
print( "a: {}\t b: {}".format(a, b))
print( "Location a[0]: {}\t Location b[0]: {}".format( id(a[0], id(b[0])))
a[0] = 20 # re-declaring the value of a[0] also changes b[0]
print( "a: {}\t b: {}".format(a, b))
我收到以下错误,但我非常确定语法是正确的
File "<ipython-input-41-b19baf924839>", line 6
a[0] = 20 # re-declaring the value of a[0] also changes b[0]
^
SyntaxError: invalid syntax
文件“”,第6行
a[0]=20#重新声明a[0]的值也会更改b[0]
^
SyntaxError:无效语法
第5行缺少一个右括号:应该是
# understanding how lists are stored
a = [5, 10]
b = a
print( "a: {}\t b: {}".format(a, b))
print( "Location a[0]: {}\t Location b[0]: {}".format( id(a[0]), id(b[0])))
a[0] = 20 # re-declaring the value of a[0] also changes b[0]
print( "a: {}\t b: {}".format(a, b))
正如@justgoodin所提到的,在第5行末尾需要一个闭合括号。你有4个空缺,只有3个空缺。
更改为:
print( "Location a[0]: {}\t Location b[0]: {}".format( id(a[0], id(b[0]))))
现在收到
a: [5, 10] b: [5, 10]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-42-f158d5c60d3e> in <module>
3 b = a
4 print( "a: {}\t b: {}".format(a, b))
----> 5 print( "Location a[0]: {}\t Location b[0]: {}".format( id(a[0], id(b[0]))))
6 a[0] = 20 # re-declaring the value of a[0] also changes b[0]
7 print( "a: {}\t b: {}".format(a, b))
TypeError: id() takes exactly one argument (2 given)
a:[5,10]b:[5,10]
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在里面
3 b=a
4打印(“a:{}\t b:{}”。格式(a,b))
---->5打印(“位置a[0]:{}\t位置b[0]:{}”。格式(id(a[0],id(b[0]))
6 a[0]=20#重新声明a[0]的值也会更改b[0]
7打印(“a:{}\t b:{}”。格式(a,b))
TypeError:id()只接受一个参数(给定2个)
第5行缺少结束括号。id(a[0]
缺少结束括号通常,如果遇到对您没有意义的语法错误,请在前几行中搜索问题。公式看起来错误,请再次尝试复制上述解决方案