r/learnpython • u/sillycups • Aug 27 '18
Create an empty list
Good monday everyone!
I just started university and is learning python. I have no experience with the language whatsoever so i was hoping on getting some help here :)
We got an assignment to get used to some of the basic functions. The task is:
Create a program which starts with an empty list and ends up with a list
containing the numbers 1-10.000. This should not be done manually like
mylist=[1,2,...,10.000]. Hint use a for-loop and append.
Been stuck at this for hours now.
appreciate all answers :)
5
Aug 27 '18
Also, Python Crash Course has an excellent chapter on Lists and associated methods. Plus, and apologies if this sounds cryptic, but if you know how to create a list with elements, you already know the syntax to create an empty list.
Edit: Grammar
0
2
u/sheep1996 Aug 27 '18
Try googling "python populate list". You'll see how basic loops work in answers there.
1
0
u/noodlesource Aug 27 '18
You can create an empty list:
my_list = [] You can then use a for loop to iterate over a block of code, appending a number to your list each iteration. I'd suggest taking a look at how "for" loops work if you have never coded before.
0
Aug 27 '18
[deleted]
1
u/sillycups Aug 27 '18
I got some good advice on what to google now. I will try to figure it out for myself first :)
0
Aug 27 '18
[deleted]
3
u/Adantingtask Aug 27 '18
Try to guide OP to a solution instead of providing one directly.
in case you are wondering why you are being downvoted, this is taken from the commenting guidlines.
8
u/julsmanbr julsmanbr Aug 27 '18
What have you tried already?
Have you learned about for loops and the append method for lists?