learning python. learning defining functions . need help

Chris Angelico rosuav at gmail.com
Fri Jul 22 09:24:27 EDT 2016


On Fri, Jul 22, 2016 at 11:13 PM, Dennis Lee Bieber
<wlfraed at ix.netcom.com> wrote:
>         Now... Going much beyond the assignment (if you were having trouble
> with the assignment, this will seem like magic) [Python 2.7]:

I'm not sure, but I think your code would become Py3 compatible if you
just change your prints. Which I'd recommend - it's not difficult to
just always print a single string, and most example code is ASCII-only
and has no difficulty with the bytes/unicode distinction. But, point
of curiosity...

> class Refrigerator(object):
>     def __init__(self, stock=None):
>         if stock is None or type(stock) != type(dict()):
>             self._stock = dict()
>         else:
>             self._stock = stock

... why do you call up "type(dict())"? Why not either just "dict" or "type({})"?

ChrisA



More information about the Python-list mailing list