Important Notice:

Name Error

Name Error

23 views 1 min read

Name Error (नेम एरर) :-

NameError तब आती है जब Program में किसी ऐसे Variable, Function या Object का उपयोग किया जाता है जिसे Python पहचान नहीं पाता। इसका मुख्य कारण यह होता है कि वह नाम (Name) पहले Define नहीं किया गया होता या गलत लिखा गया होता।

English:

A NameError occurs when a program tries to use a variable, function, or object that Python cannot recognize. This usually happens because the name has not been defined or is misspelled.

 

Wrong Example 1: Undefined Variable :-

 
print(name)
 

Output:

 
NameError: name 'name' is not defined
 

Correct Example

name = "Rahul"
print(name)

Output:

 
Rahul
 

Wrong Example 2: Misspelled Variable Name :-

 
number = 10
print(numbr)

Output:

 
NameError: name 'numbr' is not defined
 

Correct Example

 
number = 10
print(number)
 

Output:

 
10
 

Wrong Example 3: Case Sensitivity :-

 
Name = "Python"
print(name)
 

Output:

 
NameError: name 'name' is not defined
 

Correct Example -

 
Name = "Python"
print(Name)
 

Output:

 
Python
 

Wrong Example 4: Undefined Function :-

 
hello()
 

Output:

 
NameError: name 'hello' is not defined
 

Correct Example

 
def hello():
    print("Hello Python")

hello()
 

Output:

 
Hello Python

Related Notes