Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: learning python. learning defining functions . need help Date: Sat, 23 Jul 2016 01:35:56 +1000 Lines: 33 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 Xjwb4xnm7TZw485xveyl8QTYUJm54FOSWa8fFTIfHYtQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'defaults': 0.05; 'interpreted': 0.07; 'subject:help': 0.07; 'cc:addr:python-list': 0.09; 'dict': 0.09; 'python': 0.10; 'syntax': 0.13; 'interpreter': 0.15; '(well,': 0.16; '2016': 0.16; '23,': 0.16; 'anyway).': 0.16; 'chris,': 0.16; 'dictionary.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'justin': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'saying.': 0.16; 'subject:python.': 0.16; 'wrote:': 0.16; 'subject:need': 0.18; 'typing': 0.18; 'why.': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; '(like': 0.23; 'sat,': 0.23; 'header:In-Reply- To:1': 0.24; 'command': 0.26; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'subject:learning': 0.29; 'equal': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'replace': 0.35; 'set.': 0.35; 'but': 0.36; 'should': 0.36; 'stock': 0.36; 'subject:: ': 0.37; 'mean': 0.38; 'your': 0.60; 'course': 0.62; 'subject:. ': 0.67; 'jul': 0.72; 'chrisa': 0.84; 'dict()': 0.84; 'dict,': 0.84; 'dict.': 0.84; 'subject: . ': 0.84; 'walters': 0.84; 'to:none': 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:cc; bh=k2HuYZ+8tYENGXPQNNtqR4aaceCwRf8FILkbQ/g8feA=; b=jbyzRcR9QOkg+a3nVxnlE+Lz+1SFx7wqZfwIUTJekMkA07agUTJUA09fK5GXzIIjsN KVb+TGM5ySbH+XdLLvhC5BBGSpfxtVymQlyk04+ePvhhFAHrZmSAJ7CH3P2F7plGkT9g gMYqJClKDps+LWH8yEyGFZdLfAKOYyadLd1rV6ZtgX7v3bhhRjtGtUMbkA5sjZR9/zPk oSZffHc8dtrjBW2+yATX2Z9vadrygZ6vTtpYLOTU52zvGjgi95NyHEUNmehimJ7xHZNK Js8PXH7IS8NvcJ5jPYIh81Qm3s7dbffGM6JLStSs+lTpAI9SlT+xmIlrImCyQrmOx3u9 pj6g== 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:cc; bh=k2HuYZ+8tYENGXPQNNtqR4aaceCwRf8FILkbQ/g8feA=; b=Mq4xUATCqdc7bjb+Wm03u0nvCsVk0BRG0r8+j0HnO7QGkTCQxEGkyXgfrFYziIsNt/ J46A/E+C/U7jmGzBqyL0mzVuQuDhzDbUsI2K3hIi+DcwcAeIfpO3Ldd8htmZLeYJ8V13 QB2kGM4V7htmEfz1/BE0VgaJMwwWziKlLSv9FT/jA56kri6jJ6tEX4/1VSOKQFhFMTgz geypx6P67qsU+Dr7aTRpUqycqgnZwbiwNAx2IC1hDY6JY6hgDKtFeIM/x5vc1UhMUFSH DW7FZyy5FIV4QsAXEZnDni8/Mom8C8P3fS2yUb/fdIDH+LQ8SS3hdTnRVOOpyc5cpc5P grOg== X-Gm-Message-State: AEkoouuHOZMJJZwSHE4p8yn5XaY12+ayt5gJvAKj2rBYtKdkk4p87SQNLQiL5hgring9P1fhZFiUtRN8QUPm2w== X-Received: by 10.28.45.69 with SMTP id t66mr2974313wmt.41.1469201757579; Fri, 22 Jul 2016 08:35:57 -0700 (PDT) In-Reply-To: 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:111762 On Sat, Jul 23, 2016 at 1:21 AM, justin walters wrote: > 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. Of course the type of {} is not equal to an empty dict, but it *will* be equal to dict itself: >>> type({}) == dict True And it's not ambiguous; it's always going to mean a dictionary. There's no empty set syntax in Python (well, not as of 3.6, anyway). > You could also replace that line with: > > if stock is None or type(stock) != dict: That's exactly what I was saying. Barring shenanigans (like shadowing 'dict' with a function or something), type(dict()) will always be dict. ChrisA