Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

create an empty list in python with certain size

Asked by Yamamoto Saito Jul 27, 2021 1.6K views 1 answer
Share

About this question

I want to create an empty list (or whatever is the best way) that can hold 10 elements.

After that I want to assign values in that list, for example this is supposed to display 0 to 9:

s1 = list();
for i in range(0,9):
s1[i] = i
print s1

But when I run this code, it generates an error or in another case it just displays [] (empty).

Can someone explain how to create python empty list of size n? Why getting this error?

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.