Python NameError: 名称 'Print' 未定义

10 投票
12 回答
87832 浏览
提问于 2025-04-16 13:42

我在解释器上运行一个打印命令,结果出现了这个错误:

Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> Print ("Hello World")
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    Print ("Hello World")
NameError: name 'Print' is not defined
>>> Print ('Hello World')
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    Print ('Hello World')
NameError: name 'Print' is not defined
>>> Print("Hello World")
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    Print("Hello World")
NameError: name 'Print' is not defined

为什么Print会没有定义呢?

12 个回答

4

看起来你的“Print”写错了,应该用小写的print。

8

Python是区分大小写的。

print('Hello World')

18

在Python中,函数和关键字的名字是区分大小写的。这意味着你写的Printprint是两个不同的东西。看起来你应该用print,而不是Print

撰写回答