I'm new to Python. How how can I append a counter to a variable? ctr = 3 variable = variable3

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions.

A community for students.

I'm new to Python. How how can I append a counter to a variable? ctr = 3 variable = variable3

MIT 6.00 Intro Computer Science (OCW)
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

What are you trying to do? I don't quite understand the question. If you are trying to add 3 to any variable you can just use variable +=3 So, >>> ctr = 0 >>> ctr += 3 >>> ctr += 3 >>> print ctr 6
variable = [] variable.append(ctr) ??????
when you tried it did you get something like this in the traceback?: TypeError: cannot concatenate 'str' and 'int' objects maybe this: v = "variable" + str(ctr)

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

If I'm understanding the question correctly, you are trying to programmatically create a variable name using information stored in another variable. While it is possible (with some magic) it's not recommended. Instead I would suggest storing the information into a dictionary or, if you are accessing sequential data, a list. e.g. variable = [] variable.append('ham') variable.append('eggs') variable.append('toast') print "For breakfast I'd like %s, %s and no %s" % (variable[1], variable[2], variable[0])
You can't. You just increment the value assigned to a variable ctr = ctr + 1 or ctr += 1 for short. You can assign the value of a variable to another. a = 5 ctr += a That's about it. The append method is for lists, for adding an object on to the end of an existing sequence of objects.

Not the answer you are looking for?

Search for more explanations.

Ask your own question