Borislav Hadzhiev
Wed Apr 20 2022·1 min read
Photo by Anthony Delanoix
The Python "NameError: name 'Print' is not" occurs when we misspell the
built-in print()
function. To solve the error, make sure to spell print
in
all lowercase letters and don't declare a variable named print
in your code.
Here is an example of how the error occurs.
# ⛔️ NameError: name 'Print' is not defined. Did you mean: 'print'? Print('Hello world') # 👈️ spelled print() with capital P
To solve the error, we have to spell the print() function in all lowercase letters.
print('Hello world')
Names of variables, functions and classes are case-sensitive in Python, so the
identifiers print
and Print
are completely different.
print
in your code, e.g. print = 'something else'
.Re-declaring a variable that's associated with a built-in function can lead to some very confusing behavior.
Another thing to watch out for is to not name your modules using a reserved
name, e.g. math.py
because that could shadow a module you are trying to
import.
The print()
function is always available in Python and does not require an
import statement, so if spelled correctly (all lowercase letters), the error
should be resolved.