NameError: name 'Print' is not defined in Python

avatar

Borislav Hadzhiev

Last updated: Apr 20, 2022

banner

Photo from Unsplash

NameError: name 'Print' is not defined in Python #

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.

nameerror name print is not defined

Here is an example of how the error occurs.

main.py
# ⛔️ 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.

main.py
print('Hello world')

Names of variables, functions and classes are case-sensitive in Python, so the identifiers print and Print are completely different.

Make sure you haven't declared a variable named 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.

Conclusion #

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.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.