python - Why is this list not 'saving' after I execute the function? -


So I'm only coding for a few weeks and today, I was messing around writing an algorithm in Python The list that fills the empty list. I have written this:

  def wth (a, b): list = [] i = 0 j = b while len (list) & lt; A: list.insert (i, j) i = I + 1J = J + 1 return list  

This works, for example:

 < [10, 11, 12] However, if I want to keep this list and want to do something for it, then it just returns to an empty list: [13] 14, 15, 16, 17, 18, 19]  

  print list []  

Why is it so? Many thanks in advance.

If you want to use the result of a function, you must assign it to

Instead of this code, you can simply use for a variable like

  new_list = wth (a, b)  b)  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -