[Tutor] Str Method

Ashley Fowler afowler2 at broncos.uncfsu.edu
Thu Nov 1 16:34:56 CET 2012


Hello I am trying to add a str method to a Set ADT implementation to allow a user to print the contents of a set. However the resulting string should look like that of a list. except I am suppose to use curly brackets to surround the elements.

For an example...
>>> set1 = Set()
>>> print(set1)
{}


Question is how do you implement the "curly brackets" in my str method?

This is what I have so far...

def __init__( self, *initElements ):
    self._theElements = list()

def __str__(self):
     return self._theElements
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121101/60391761/attachment.html>


More information about the Tutor mailing list