“打印"在Python 3中引发无效的语法错误 [英] "print" throws an invalid syntax error in Python 3

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

问题描述

我是python的新手.我一直在从事Codecademy的课程.我目前也在使用Pydev/LiClipse.

I am brand new to python. I have been working on the courses on Codecademy. I am also currently using Pydev / LiClipse.

在Codecademy的第一课中,它希望您将变量鹦鹉设置为挪威蓝".然后,它希望您使用len字符串方法打印鹦鹉的长度.这很简单,我马上就得到了答案:

In one of the first lessons on Codecademy it wants you to set the variable parrot to "Norwegian Blue". Then it wants you to print the length of parrot using the len string method. It is very simple, and I got the answer right away with:

parrot = "Norwegian Blue"
print len(parrot)

当我将完全相同的代码放入LiClipse时,它返回:

When I put the exact same code into LiClipse it returned:

SyntaxError:语法无效

SyntaxError: invalid syntax

当我将其更改为以下内容时,它就可以在LiClipse中使用:

It work in LiClipse when I changed it to:

打印(len(parrot))

print (len(parrot))

有人可以让我知道为什么这可以在代码学院工作,但不能在LiClipse中工作,为什么还要加上括号来修复它?

Can someone let me know why that worked in codecademy, but not in LiClipse, and why adding the parenthesis fixed it?

推荐答案

听起来Pydev/LiClipse使用的是Python 3,而Codeacademy使用的是python 2.x或其他旧版本.现在,将python从2.x更新到3时所做的更改之一是打印.

It sounds like Pydev/LiClipse is using Python 3 while Codeacademy is using python 2.x or some other older version. One of the changes made when python updated from 2.x to 3 was print is now a function.

Python 2:

print "stuff to be printed"

Python 3:

print("stuff to be printed")

这篇关于“打印"在Python 3中引发无效的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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