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

  • SEARCH
  • Home
  • 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 716961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:21:30+00:00 2026-05-14T05:21:30+00:00

pt=[2] pt[0]=raw_input() when i do this , and give an input suppose 1011 ,

  • 0
pt=[2]
pt[0]=raw_input()

when i do this , and give an input suppose 1011 , it says list indexing error- ” list assignment index out of range” . may i know why? i think i am not able to assign a list properly . how to assign an array of 2 elements in python then?

  • 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-05-14T05:21:31+00:00Added an answer on May 14, 2026 at 5:21 am

    Try this:

    pt = list()
    pt.append(raw_input())
    pt.append(raw_input())
    print pt
    

    You now have two elements in your list. Once you are more familiar with python syntax, you might write this as:

    pt = [raw_input(), raw_input()]
    

    Also, note that lists are not to be confused with arrays in Java or C: Lists grow dynamically. You don’t have to declare the size when you create a new list.

    BTW: I tried out your example in the interactive shell. It works, but probably not as you expected:

    >>> pt = [2]
    >>> pt[0] = raw_input()
    1011
    >>> pt
    ['1011']
    

    I’m guessing you thought pt = [2] would create a list of length 2, so a pt[1] = raw_input() would fail like you mentioned:

    >>> pt = [2]
    >>> pt[0] = raw_input()
    1011
    >>> pt[1] = raw_input() # this is an assignment to an index not yet created.
    1012
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    IndexError: list assignment index out of range
    

    Actually, pt = [2] creates a list with one element, having the value 2 at index 0:

    >>> pt = [2]
    >>> pt
    [2]
    >>>
    

    So you can assign to the index 0 as demonstrated above, but assigning to index 1 will not work – use append for appending to a list.

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

Sidebar

Related Questions

I'm trying something like this Output.py print Hello Input.py greeting = raw_input(Give me the
I'm trying to let the user input commands at a console using raw_input(), this
I make this program :: #include<stdio.h> char *raw_input(char *msg); main() { char *s; *s
Since input and raw_input() stop the program from running anymore, I want to use
Possible Duplicate: raw_input and timeout raw_input() will wait for user input. How to make
I'm trying to do: raw_input(Anyone Home?) But I'm getting syntax error! I'm using Python
Consider this code: >>> num = int(raw_input('Enter the number > ')) If the user
I have this little credit card validation program where the user has to input
def complex(): answer = raw_input(Would you like to run this program?) answer = answer.lower()
I have this python program that adds strings to integers: a = raw_input("Enter a:

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.