Python Fix – NameError: name ‘Anything’ is not defined

Error – NameError: name ‘Welcome’ is not defined

This is another one of the most basic error you will get usually in Python, For Example, You wrote below Code and getting the error:

 

Hint:

The Hint is there in the Error Code itself , Since it is telling that Object is Not defined.

NameError: name ‘Anything’ is not defined


How to fix ?

Follow our Quick Guide to fix NameError: name ‘Anything’ is not defined

Reason:

There could be Two reasons when you’re getting this error.

1 – When you try to print some message.

2 – When you try to print a Variable value Which is not defined.

Solution:

1- If you try to print some message , Use Double quotes (“) Or single quotes (‘).

For Example: I try to print Welcome, Using Double quotes in Below Code.

 

2 – If you want to print some variable, Then Please Define it first and then print it.

For Example: I will take a variable name Welcome and store a message into it and will try to print the message through variable name.

 

Since the Variable “Welcome” is already defined in First line ,the value it is holding got printed.

 

Also Read :Why is Python chosen from other programming languages ​​for AI and machine learning?