Python Forum
'int' object does not support item assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'int' object does not support item assignment
#5
(Aug-13-2019, 01:09 PM)shane1236 Wrote: yes I want the same as you said can you just code it for me. Also it runs when I put app=[], however, it doesnot print anything can you look into that??

(Aug-13-2019, 12:33 PM)buran Wrote: I want the same as below post said, however, Also it runs when I put app=[], however, it doesnot print anything can you look into that??

Sorry, I made a mistake. You should use the .append() method (not the .push() method, that is from JavaScript Silenced).

Did you forget to call the function?

def new():
    app = []
    for i in range(10):
      app.append(i+1)
    print(app)

new()
I wouldn't have passed "app" in as a parameter to the function, as you did. I suspect you also meant to "print(app)" only once, instead of putting it inside the for loop.

By the way, this might be a bit more advanced, but for future reference, you can cut all those lines down to one by using a list comprehension as such:

app = [i for i in range(1, 11)]
print(app)
And that will give you the same output Wink
Reply


Messages In This Thread
RE: 'int' object does not support item assignment - by epokw - Aug-13-2019, 01:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Remove an item from a list contained in another item in python CompleteNewb 19 5,954 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  Error: int object does not support item assignment ankita_nthu 2 14,061 Jul-07-2019, 02:14 PM
Last Post: ankita_nthu
  How do I use this? TypeError: 'NoneType' object does not support item assignment ejected 9 22,472 Mar-26-2019, 05:06 AM
Last Post: ejected
  ValueError: This COM object does not support events. meenakshi11 0 3,972 Mar-08-2018, 09:42 AM
Last Post: meenakshi11
  'str' object does not support item assignment SolaVitae 1 9,866 Jul-28-2017, 06:03 AM
Last Post: buran

Forum Jump:

User Panel Messages

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