i want to create a StringList class where i can call following functions:
s1 = StringList()
s1.strings.append('a string')
a string has to be created as a list, and i want to be able to add strings to that list and later print out the string plus the lengths of the string
so far i created the class // thx to the answer i edited it so far
class StringList:
def __init__(self):
self.strings = []
self.lenghts = 0
edit: so far i have (thx to comments and solution)
class StringList:
def __init__(self):
self.strings = []
def add_string(self, string_value):
self.strings.append(string_value)
which is able to do
s1.add_string('a string')
now comes my problem with lengths. i cant get it to work.
when using it like this:
class StringList:
def __init__(self):
self.strings = []
def add_string(self, string_value):
self.strings.append(string_value)
def lengths(self):
return len(self.string_value)
following shows up
>>> s1 = StringList()
>>> s1.add_string('a string')
>>> print(s1.strings, s1.lengths)
['a string'] <bound method StringList.lengths of <__main__.StringList object at 0x03566CB0>>