“打印"附近的语法错误? [英] SyntaxError near "print"?

查看:35
本文介绍了“打印"附近的语法错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我为什么这会在空闲时给我语法错误?

can anybody please tell me why this is giving me syntax error in idle?

def printTwice(bruce):
    print bruce, bruce

语法错误:无效语法

推荐答案

检查正在使用的 Python 版本;变量 sys.version 包含有用的信息.

Check the version of Python being used; the variable sys.version contains useful information.

这在 Python 3.x 中是无效的,因为 print 只是一个普通函数,因此需要括号:

That is invalid in Python 3.x, because print is just a normal function and thus requires parenthesis:

# valid Python 3.x syntax ..
def x(bruce): print(bruce, bruce)
x("chin")

# .. but perhaps "cleaner"
def x(bruce):
    print(bruce, bruce)

(Python 2.x 中的行为是不同的,其中 print 是一个特殊声明.)

(The behavior in Python 2.x is different, where print was a special statement.)

这篇关于“打印"附近的语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆