Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #111762

Re: learning python. learning defining functions . need help

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
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 <mailman.57.1469201759.22221.python-list@python.org> (permalink)
References <432aeb03-ea14-4ece-8e5b-a7521cf12b84@googlegroups.com> <ji44pbpbaj6olkqcq832ivm7q7gl5d1aca@4ax.com> <CAPTjJmq6nnqp3434HNkxZLPm-igt-vk76u1GZVsr7euhWd4f8Q@mail.gmail.com> <CAO1D73GxUMSwRZvggewY8o-3GLpSMZHAyGD18by1dy-CqyGhpw@mail.gmail.com> <CAPTjJmrsCAccd5y9d4kJwU0peSgvCWEgKc_pN4kswhOkvQpG5Q@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de Xjwb4xnm7TZw485xveyl8QTYUJm54FOSWa8fFTIfHYtQ==
Return-Path <rosuav@gmail.com>
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 <CAO1D73GxUMSwRZvggewY8o-3GLpSMZHAyGD18by1dy-CqyGhpw@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAPTjJmrsCAccd5y9d4kJwU0peSgvCWEgKc_pN4kswhOkvQpG5Q@mail.gmail.com>
X-Mailman-Original-References <432aeb03-ea14-4ece-8e5b-a7521cf12b84@googlegroups.com> <ji44pbpbaj6olkqcq832ivm7q7gl5d1aca@4ax.com> <CAPTjJmq6nnqp3434HNkxZLPm-igt-vk76u1GZVsr7euhWd4f8Q@mail.gmail.com> <CAO1D73GxUMSwRZvggewY8o-3GLpSMZHAyGD18by1dy-CqyGhpw@mail.gmail.com>
Xref csiph.com comp.lang.python:111762

Show key headers only | View raw


On Sat, Jul 23, 2016 at 1:21 AM, justin walters
<walters.justin01@gmail.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

learning python. learning defining functions . need help sigmaphine1914@gmail.com - 2016-07-21 19:27 -0700
  Re: learning python. learning defining functions . need help Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-07-22 09:13 -0400
  Re: learning python. learning defining functions . need help Chris Angelico <rosuav@gmail.com> - 2016-07-22 23:24 +1000
  Re: learning python. learning defining functions . need help justin walters <walters.justin01@gmail.com> - 2016-07-22 08:21 -0700
    Re: learning python. learning defining functions . need help Steven D'Aprano <steve@pearwood.info> - 2016-07-23 11:44 +1000
  Re: learning python. learning defining functions . need help Random832 <random832@fastmail.com> - 2016-07-22 11:35 -0400
  Re: learning python. learning defining functions . need help Chris Angelico <rosuav@gmail.com> - 2016-07-23 01:35 +1000
  Re: learning python. learning defining functions . need help "D'Arcy J.M. Cain" <darcy@Vex.Net> - 2016-07-22 11:41 -0400
  Re: learning python. learning defining functions . need help MRAB <python@mrabarnett.plus.com> - 2016-07-22 19:36 +0100
  Re: learning python. learning defining functions . need help Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-07-22 20:04 -0400
  Re: learning python. learning defining functions . need help Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-07-23 11:39 -0400

csiph-web