Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8255623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:35:17+00:00 2026-06-08T01:35:17+00:00

Instead of appending a value by list.append() to the list , Why can;t I

  • 0

Instead of appending a value by list.append() to the list , Why can;t I assign a value to it like this?

In [24]: def a():
   ....:     a1=[5]
   ....:     print a1[0]
   ....:     

In [25]: a()
5

In [28]: def a():
   ....:     a1=[5]
   ....:     a1[1]=12
   ....:     print a1[1]
   ....:     

In [29]: a()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/home/dubizzle/webapps/django/dubizzle/<ipython-input-29-72f2e37b262f> in <module>()
----> 1 a()

/home/dubizzle/webapps/django/dubizzle/<ipython-input-28-681d86164e67> in a()
      1 def a():
      2     a1=[5]
----> 3     a1[1]=12
      4     print a1[1]
      5 

IndexError: list assignment index out of range
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:35:19+00:00Added an answer on June 8, 2026 at 1:35 am

    a=[5] creates a list with size 1. The following is valid:

    a[0] = 1
    

    but you cannot alter the size of the list by just assigning a value to a given, non-existing position.

    You can extend the list, though, by using append or +=:

    a.append(2)
    a += [2]
    

    You can also pre-allocate a list with a given size:

    a = [0] * 4
    

    That would give you a list with four elements (all zeros). After that you could change any element in the range 0-3.

    As a reference, here you have some documentation on lists from python.org.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Instead of posting in Angular mailing list, I think this may be more of
Instead of using an interface like this: public interface IStartable { void Start(); void
I can create a literal long by appending an L to the value; why
Instead of having nested callbacks in JS, I would like to fire and listen
I'm getting mad with list indexes, and can't explain what I'm doing wrong. I
I start with this markup: <div> <span> <label for=Item[0]>Item #1</label> <input type=text value= name=Item
I expect the following function to output a sanitized list of tags, but instead
I have this table cell, to which I'm appending a radio button through jQuery.
I am using this zip code verification script I found online but instead of
I have some html element like these: <table id=myTable></table> <select name=mySelect> <option value=1>1</option> <option

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.