(Aug-13-2019, 01:09 PM)shane1236 Wrote: yes I want the same as you said can you just code it for me. Also it runs when I put app=[], however, it doesnot print anything can you look into that??
(Aug-13-2019, 12:33 PM)buran Wrote: I want the same as below post said, however, Also it runs when I put app=[], however, it doesnot print anything can you look into that??
Sorry, I made a mistake. You should use the .append() method (not the .push() method, that is from JavaScript ).
Did you forget to call the function?
def new(): app = [] for i in range(10): app.append(i+1) print(app) new()I wouldn't have passed "app" in as a parameter to the function, as you did. I suspect you also meant to "print(app)" only once, instead of putting it inside the for loop.
By the way, this might be a bit more advanced, but for future reference, you can cut all those lines down to one by using a list comprehension as such:
app = [i for i in range(1, 11)] print(app)And that will give you the same output