Python Forum
List not passing between methods inside a class definition
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List not passing between methods inside a class definition
#4
Your last line should be c.add(d). You want to call it from the instance, so the instance parameter (self) is automatically filled. Also note that the print in the add method should be print(self.a), since a is an attribute of the instance. Finally, what I was talking about with the a parameter to __init__ was more like this:

def __init__(self, a = None):
    if a is None:
        a = []
    self.a = a
    print(a)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: List not passing between methods inside a class definition - by ichabod801 - Oct-15-2017, 12:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Return a definition samh625 6 2,631 Jul-28-2020, 08:32 AM
Last Post: samh625
  Please, how do I call the method inside this class Emekadavid 1 1,781 Jun-26-2020, 01:26 PM
Last Post: Yoriz
  Child Class, Loop list bjornnotborg 2 2,530 Aug-28-2019, 12:31 PM
Last Post: bjornnotborg
  Methods that return the highest score from the list erfanakbari1 7 7,450 Mar-26-2019, 08:32 PM
Last Post: aankrose
  New to coding. An error occurs with no definition westernwhiskey 4 3,180 Mar-15-2018, 12:37 PM
Last Post: westernwhiskey
  How do you compute tf-idf from a list without using the counter class syntaxkiller 8 5,460 Dec-01-2017, 05:24 PM
Last Post: nilamo
  trouble importing class definition from one .py into another ijosefson 3 3,475 Oct-16-2017, 08:24 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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