Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: justin walters Newsgroups: comp.lang.python Subject: Re: learning python. learning defining functions . need help Date: Fri, 22 Jul 2016 08:21:17 -0700 Lines: 45 Message-ID: References: <432aeb03-ea14-4ece-8e5b-a7521cf12b84@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de x3uiJZ8Z+zLLLvAS2kp8tggj/iojhabb5mlmzROTh49A== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'defaults': 0.05; 'assignment': 0.07; 'interpreted': 0.07; 'subject:help': 0.07; 'cc:addr:python-list': 0.09; '22,': 0.09; 'dict': 0.09; 'def': 0.13; 'interpreter': 0.15; '2016': 0.16; 'chris,': 0.16; 'distinction.': 0.16; 'py3': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:python.': 0.16; '\xc2\xa0if': 0.16; 'wrote:': 0.16; 'string,': 0.18; 'subject:need': 0.18; 'typing': 0.18; 'why.': 0.18; '>': 0.18; 'email addr:gmail.com>': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'command': 0.26; 'chris': 0.26; 'compatible': 0.27; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'subject:learning': 0.29; 'sure,': 0.29; "i'm": 0.30; 'print': 0.30; 'url:mailman': 0.30; 'code': 0.30; "i'd": 0.31; 'skip:_ 10': 0.32; 'point': 0.33; 'class': 0.33; 'url:python': 0.33; 'url:listinfo': 0.34; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'trouble': 0.35; 'could': 0.35; 'replace': 0.35; 'set.': 0.35; 'but': 0.36; 'should': 0.36; 'url:org': 0.36; 'stock': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'beyond': 0.37; 'seem': 0.37; 'why': 0.39; 'url:mail': 0.40; 'your': 0.60; 'difficulty': 0.66; 'skip:\xc2 10': 0.67; 'subject:. ': 0.67; 'jul': 0.72; 'chrisa': 0.84; 'dict()': 0.84; 'now...': 0.84; 'subject: . ': 0.84; 'dennis': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=HnPpvFDcH9nQZo5S1SFY8/SKeB2I8SvTqs3zH6GFkSw=; b=wCadW/R3W4EF9tptr7akR0k+RvBfiOHAaUAi2TyZnbQsxMLyy1pURQwNJBtrIXD73Z f2i27hSyaIzOuKRP7wwSlshjxdpMAivnKnGO4rdjRPx8gVGydyQE11GVf4DoYNQuzB0Y 0obSsWM/nFWEHfsxJtglmeRx1KRiX2u2I6/vc2JgOXHEpETY05D5cVtNLrKVrovwTYhI GxbqnoVG3uTSfKJxIaaQ199OOr7sslF9QCEPTrB/HABoMU/Q4pAxLHP6IFY0Q4hWwEcj R662IG4SX4w7Yg9pwenLQxs/NjlD7nL7Qg7lFzBYmF51m19Wwfb6WAVGxdHHt8Bm9xWO iOhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=HnPpvFDcH9nQZo5S1SFY8/SKeB2I8SvTqs3zH6GFkSw=; b=Ww5evxkV4LeAU4YGL/QespnDV8mnooB2BtwmPzm4g9LiKWhSYliIh1f8Thvno+sV3O ruXmdsRw/fXM8lorzHBU3r9x1ix61n/eNsPmYZWD9cEaHMilvtq70NhMjv3dSM4atVun i73+9lLLEwqoUlP0qpeaSFmmph4PqiLaB6V22svDR2muEK/UiCUGxVWBSuDgCZLGl/F+ lD68VHgZZUcZmnTDWmOjmWK9MSK6FKNJTeUAB7G8ivPk40Z8hKUpDAcdddie9KygMQNG D9mJT1XCCHb6X+iY5NYKXXZNqvN+XzOe3M5tDFndefUojAxhIyw8IExBRafj1Gi6FdfT CvSg== X-Gm-Message-State: AEkoous8BKYRcGqcd0ZsdoezhiX83NnlvSW6HmDi+YZLg/0oVF7H9WNMjjbNhXyVyqCsI4ip507Bll2nueBJiQ== X-Received: by 10.25.152.135 with SMTP id a129mr2606897lfe.226.1469200877843; Fri, 22 Jul 2016 08:21:17 -0700 (PDT) In-Reply-To: X-Content-Filtered-By: Mailman/MimeDel 2.1.22 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <432aeb03-ea14-4ece-8e5b-a7521cf12b84@googlegroups.com> Xref: csiph.com comp.lang.python:111759 On Fri, Jul 22, 2016 at 6:24 AM, Chris Angelico wrote: > On Fri, Jul 22, 2016 at 11:13 PM, Dennis Lee Bieber > 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 > -- > https://mail.python.org/mailman/listinfo/python-list > Hi Chris, Try opening the interactive terminal on your command line and type the following: type({}) == dict() That should illustrate why. This is because simply typing '{}' could be interpreted as either a dict or a set. My interpreter defaults 'type({})' to 'dict', but it's best to not take the risk. You could also replace that line with: if stock is None or type(stock) != dict: