我是python的新手。我一直在研究 Codecademy 的课程。我目前也在使用 Pydev/LiClipse。
在 Codecademy 的第一堂课中,它希望您将变量 parrot 设置为“挪威蓝”。然后它希望您使用 len 字符串方法打印鹦鹉的长度。这很简单,我马上得到了答案:
parrot = "Norwegian Blue"
print len(parrot)
Run Code Online (Sandbox Code Playgroud)
当我将完全相同的代码放入 LiClipse 时,它返回:
语法错误:无效语法
当我将其更改为以下内容时,它在 LiClipse 中工作:
打印(len(鹦鹉))
有人可以让我知道为什么这在 codecademy 中有效,但在 LiClipse 中无效,以及为什么添加括号修复了它?
听起来 Pydev/LiClipse 使用的是 Python 3,而 Codeacademy 使用的是 python 2.x 或其他一些旧版本。python 从 2.x 更新到 3 时所做的更改之一是打印现在是一个函数。
蟒蛇2:
print "stuff to be printed"
Run Code Online (Sandbox Code Playgroud)
蟒蛇3:
print("stuff to be printed")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15690 次 |
| 最近记录: |