I get NameError: name 'array' is not defined
in python error when I want to create array, for example:
a = array([1,8,3])
What am I doing wrong? How to use arrays?
The Python "NameError: name is not defined" occurs when we try to access a variable or function that is not defined or before it is defined. To solve the error, make sure you haven't misspelled the variable's name and access it after it has been declared.
What are Python Arrays? Arrays are a fundamental data structure, and an important part of most programming languages. In Python, they are containers which are able to store more than one item at the same time. Specifically, they are an ordered collection of elements with every value being of the same data type.
The Python "NameError: name 'array' is not defined" occurs when we use the array module without importing it first. To solve the error, import from the array module before using it - from array import array . If using numpy , access array on the numpy module, e.g. np. array .
What Is a NameError in Python? In Python, the NameError occurs when you try to use a variable, function, or module that doesn't exist or wasn't used in a valid way. Some of the common mistakes that cause this error are: Using a variable or function name that is yet to be defined.
You need to import the array
method from the module.
from array import array
http://docs.python.org/library/array.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With