【问题标题】:why do i get a syntax error when print tuple?为什么打印元组时出现语法错误?
【发布时间】:2020-04-21 16:09:17
【问题描述】:

当我尝试打印元组时,我得到了无效的语法 zipped

print (zipped)
    ^

SyntaxError: 无效语法

x = (3,6,7,4,0)
y = (2,6,7,4,1)

zipped = zip(tuple((x,y))

print (zipped)

【问题讨论】:

  • zip 后面缺少括号
  • zip 的右括号:zipped = zip(tuple((x,y)))

标签: python-3.x tuples


【解决方案1】:

正如 A.J. 指出的那样。 cmets 中的 Uppal,您在 zipped 语句中缺少 )

x = (3,6,7,4,0)
y = (2,6,7,4,1)

zipped = zip(tuple((x,y)))

print (zipped)

# output
<zip object at 0x7f3f1c91c480>

【讨论】:

    猜你喜欢
    • 2016-09-01
    • 2021-04-17
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 2019-09-12
    • 2019-11-22
    • 1970-01-01
    相关资源
    最近更新 更多