【问题标题】:invalid syntax print in Python 3.3.0 [duplicate]Python 3.3.0 中的无效语法打印 [重复]
【发布时间】:2013-01-19 05:10:02
【问题描述】:

可能重复:
Syntax error on print with Python 3

我试图在 python 3 中做阶乘,无论我说什么都告诉我同样的事情“无效的语法:语法错误”......为什么它会给我一个错误?谢谢

版本是

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32

这就是我想做的事情

>>> def fact(n):
... res = 1
... while n > 1: 
... res *= n
... n -= 1
... return res

当我尝试打印时

>>> print fact(23)

它告诉我 SyntaxError: invalid syntax

【问题讨论】:

    标签: python printing syntax-error


    【解决方案1】:

    在 python 3.x 中,print 是一个函数。请改用print(fact(23))

    【讨论】:

      猜你喜欢
      • 2011-11-26
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-27
      • 2014-04-29
      相关资源
      最近更新 更多