Create an empty list in python with certain size

Python

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 why?


If you want to unleash your potential in this competitive field, please visit the Python course page for more information, where you can find the Python tutorials and Python frequently asked interview questions and answers as well.

0
Answers

Replies

There are no replies to this topic.
 

This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.
WhatsApp
To Top