python - How to add a number to a certain index in a list? -


  list = [4, 7, 5, 3]  

This list, I think, is the index of 0 in number 4, 1 in 5, 2 has 2 and 3 of 3, but how do I add a value to a personal index?

  (list [1] + 1) I thought that the above will have to do this when I print the list:  
  print (list) [4, 8, 5, 3]  

You are required to actually provide a value with = , so once you have removed the result with this addition):

  list [ 1] + = 1 # Short list [1] = List [1] + 1  

Integers are unchanging , so that you can place them in place Can not be modified. You have to allocate the name again to change its value - so here we allocate a new number which is greater than the last of 1.

Now it works with the demo:

  & gt; & Gt; & Gt; List 1 = [4, 7, 5, 3]> gt; & Gt; & Gt; List 1 [1] + = 1> & gt; & Gt; & Gt; Print (List 1) [4, 8, 5, 3]  

do not name only a variable list , this is the underlying mask


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -