I would like to turn "a"+str(1) into a1 without being a strig, so I can associate a value "a"+str(1)=2 as I do?

Asked

Viewed 49 times

1

"a"+str(1)=2
File "<ipython-input-44-929460161ba7>", line 1
    "a"+str(1)=2
                ^

Syntaxerror: can’t assign to Operator

I want to create a series of variables a1 a2 A3 an and then associate to a value each one

  • Sorry in Python 3.5 am new here

  • I don’t know much about python but I wouldn’t be simpler to use an array?

  • I want to create a series of matrices that depend on quantity of elements, each matrix I would like to put a name like this, but I’m not able to do, maybe I’m thinking wrong, I’m starting to program.

  • 1

    Hello Catia, I can’t quite understand what you’re trying to do... "a" is a literal (a string), not a variable. a1 = 2? Try to edit your question and explain better what you are trying to do.

1 answer

2


Make a list instead of trying to create variables programmatically (which is possible, but not a good idea):

a =[]
a[1] = 2

I believe that’s what you want to do.

  • That’s what I wanted to do.

  • Remember to mark as the correct answer to help others who may have the same question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.