I'm a python beginner.As per the reference book, it says name 'square' is not defined
""
Module documentation
words go here
"""
spam=40
def spare(x):
"""
function documentation
Can we have your life then?
"""
return (x**2)
Class employee:
"class documentation"
pass
print(square(4))
print(square.__doc__)
Traceback (most recent call last):
File "docstrings.py", line 16, in <module>
print(square(4))
NameError: name 'square' is not defined
(Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64bit (AMD64) on win32)
python
As metropolis commented, q and p seem to be typing q and p at def spuare(x):
.
Therefore, NameError
occurs because the function spuare
is defined but the function square
is not defined.
exceptionNameError
Sent if a local or global name is not found.This only applies to non-modified names (not spam.egg, just egg).The associated value is an error message containing a name that was not found.
Embedded Exceptions—Python 3.7.3 Documentation
© 2024 OneMinuteCode. All rights reserved.