[Tutor] Str Method
bob gailer
bgailer at gmail.com
Thu Nov 1 21:12:36 CET 2012
On 11/1/2012 11:34 AM, Ashley Fowler wrote:
> 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
Please include the class statement.
Give us an example of the desired output when theElementsis not empty.
Why not create theElements as a set to start with?
what is Set ADT? is it important that we know that?
-- Bob Gailer
919-636-4239
Chapel Hill NC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121101/0950ad38/attachment.html>
More information about the Tutor
mailing list