how to increase variable name in Python? -


I am creating a simulation program.

I manually list the Python

  var1 = [mass_a, velocity_a, velocity_a] var2 = [mass_b, velocity_b, velocity_b] ... < / Code>  

How to change the number in the variable for the loop before launching the program? Something I tried

  for category (2): print (var + str (i))   

but they do not work

always remember

if you have ever used the numbers as your example You must consider the name of the variable, you should consider an sequential index worthy data structure like array or list, to create a list in Python, we

  var = [ [Mass_a, velocity_a, velocity_a], [mass_b, velocity_b, velocity_b]]   

If you should sometimes name the variable with different suffixes like

  var_A = [mass_a, velocity_a, velocity_a] var_B = [mass_b, Velocity_b, velocity_b]   

You should consider a non-sequential index worthy data structure like helmpe or dictionary, the key of this dictionary should be different suffix and Values ​​should be assigned to the corresponding variable that we do to create a dictionary in Python

 < Code> var = {'A': [mass_a, Velocity_a, velocity_a], 'b': [mass_b, velocity_b, velocity_b]}    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -