-5

a.append([1, 2]) print(a)

NameError Traceback (most recent call last) in () ----> 1 a.append([1, 2]) 2 print(a)

NameError: name 'a' is not defined <<<<<<<<<<<<<<<<<<<<<<<<<<<

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
AM.D
  • 1
  • 2
    Well what *is* `a` supposed to be? – jonrsharpe Aug 20 '18 at 19:19
  • Welcome to StackOverflow. You need to show a complete, runnable code snippet that shows your problem. The cause of your error is almost certainly earlier in your code, not in the two lines you showed us. Read and follow [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Rory Daulton Aug 20 '18 at 19:25

1 Answers1

0

I suspect this to be part of python code!

to get this working try this:

  1. declare your variables.
  2. now you can append to the variables.
  3. This will append (put on the end) an array containing 1,2.

The code:

a = []
a.append([1,2])
print(a)

The output will be [[1,2]] and print(a[0]) will output: [1,2]

gxor
  • 335
  • 3
  • 11
  • There is no such thing as variable declaration in python. https://stackoverflow.com/questions/11007627/python-variable-declaration – jbch Aug 20 '18 at 19:39
  • @user845521 actually that's a sample python file which is already made to show me the right steps,but when i run the command on my PC it gives me that error,even from the same sample file itself. and thanks already for your time and answering.. – AM.D Aug 21 '18 at 01:21
  • @jonrsharpe (a) supposed to be an assigned value was added and giving the command to add to it the following content – AM.D Aug 21 '18 at 01:27
  • @AM.D could you add all the things you typed in to the console or upload the sample file? – gxor Aug 21 '18 at 11:01
  • @user845521 i got it solved finally! and thanks for all who tried to help me. that's encouraging to keep learning. – AM.D Aug 22 '18 at 21:01
  • How did you do it? – gxor Aug 24 '18 at 05:48