Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python newbie is asking
#1
Hie, am just a newbie to python. i downloaded pycharm as my IDE and python 3.6 installed. I have a book which I am studying but when I try to practice some of the codes it gives me errors. surprisingly even if i copy the exact code it still gives me errors. Is my IDE ok or may the code isn't correct? for example, when i copy this code (changing lists) into my ide it gives me errors >>> x= [1,1,1] x[3]=2 please help me at [email protected] Cry

(Mar-28-2018, 03:37 PM)Marcus_Gondwe Wrote: Hie, am just a newbie to python. i downloaded pycharm as my IDE and python 3.6 installed. I have a book which I am studying but when I try to practice some of the codes it gives me errors. surprisingly even if i copy the exact code it still gives me errors. Is my IDE ok or may the code isn't correct? for example, when i copy this code (changing lists) into my ide it gives me errors >>> x= [1,1,1] x[3]=2 please help me at [email protected] Cry


this is the error message

Traceback (most recent call last):
File "<input>", line 1, in <module>
IndexError: list assignment index out of range


(Mar-28-2018, 03:37 PM)Marcus_Gondwe Wrote: Hie, am just a newbie to python. i downloaded pycharm as my IDE and python 3.6 installed. I have a book which I am studying but when I try to practice some of the codes it gives me errors. surprisingly even if i copy the exact code it still gives me errors. Is my IDE ok or may the code isn't correct? for example, when i copy this code (changing lists) into my ide it gives me errors >>> x= [1,1,1] x[3]=2 please help me at [email protected] Cry

(Mar-28-2018, 03:37 PM)Marcus_Gondwe Wrote: Hie, am just a newbie to python. i downloaded pycharm as my IDE and python 3.6 installed. I have a book which I am studying but when I try to practice some of the codes it gives me errors. surprisingly even if i copy the exact code it still gives me errors. Is my IDE ok or may the code isn't correct? for example, when i copy this code (changing lists) into my ide it gives me errors >>> x= [1,1,1] x[3]=2 please help me at [email protected] Cry


this is the error message

Traceback (most recent call last):
File "<input>", line 1, in <module>
IndexError: list assignment index out of range

Thanks Satish for your answer, I really assigned to a position (3) that doesn't exist. How could I not see it. Smile
Reply
#2
>>> x= [1,1,1] x[3]=2
the >>> is showing interactive use,
the code you need to copy is:
x = [1,1,1]
x[2] = 2
Remember index starts with 0, so x[3] doesn't exist

if you want to add another element, use append:
x = [1,1,1]
x.append(2)
Reply
#3
Thanks Laz60+. can you share me ur email address so as i come back you when I need help? if its ok with you. even a whatsapp number can help. my email is [email protected] whatsapp on +265888925935
Reply
#4
I Don't do that!
Reply
#5
anyways thanks bro. I appreciate.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python newbie laleebee 2 1,316 May-24-2022, 01:39 PM
Last Post: laleebee
  Newbie on Python syntax rud0lp20 6 2,938 Apr-21-2020, 04:26 PM
Last Post: jefsummers
  python newbie marcush929 2 2,596 Jan-01-2020, 08:06 AM
Last Post: marcush929
Smile Help needed. Python Newbie!, it will be fun. knightdea 3 2,624 Oct-13-2019, 08:50 AM
Last Post: perfringo
  Python Linting (newbie) LieveHeer 2 2,615 Jan-24-2019, 05:36 PM
Last Post: LieveHeer
  Newbie ? Python 3 Input() jlgrunr 1 2,452 Feb-17-2018, 10:26 PM
Last Post: Gribouillis
  Python Newbie phylon 1 30,032 Jan-09-2018, 10:46 AM
Last Post: Gribouillis
  NEWBIE HELP: How to tell Python when to use a function BoaVenom18 4 5,409 Dec-17-2016, 09:00 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020