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: Fri, 22 Jul 2016 23:24:27 +1000 Lines: 21 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 u9eqVlQEQuOy1o8nvgMLqgI9VAkTUDUq4HuMHlKQxCgg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'assignment': 0.07; 'subject:help': 0.07; 'cc:addr:python-list': 0.09; '22,': 0.09; 'def': 0.13; '2016': 0.16; 'distinction.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'py3': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:python.': 0.16; 'wrote:': 0.16; 'string,': 0.18; 'subject:need': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'header:In-Reply-To:1': 0.24; 'example': 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; 'code': 0.30; "i'd": 0.31; 'skip:_ 10': 0.32; 'point': 0.33; 'class': 0.33; 'received:google.com': 0.35; 'trouble': 0.35; 'but': 0.36; 'stock': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'beyond': 0.37; 'seem': 0.37; 'why': 0.39; 'your': 0.60; 'difficulty': 0.66; 'subject:. ': 0.67; 'jul': 0.72; 'chrisa': 0.84; 'dict()': 0.84; 'now...': 0.84; 'subject: . ': 0.84; 'to:none': 0.91; '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:cc; bh=C/Qeninm4k7erBn5g6OF9DbDV+h2Q7Xz/3gVheNJpxY=; b=owl13HT1KGQuIrQrH6etp83MwG4FlgNV7NefoW/cwoPnvSHfMPR+dyIrV9RhitsNRL qDVvIylbItW4yRC4chh5mNmhNRh4MhbgUOlnPXQ5RzeuhGurou308PvanznghYtTXci1 WuGE2AS8Gb3LnCd+bRuwcFFaaXAPXxySRQV/9s09vFsu59GNzKlvzBmCjjhr9YwImCAZ YnjJRsLpMzcZyjBc5vCmpsWvuYDZEQhubRqrY57feFFLXhgXzNZlAoBfI8ZOlSZym1WW +0GU0AeSTxkqvroPXSeaND9MjmeVkLShgO6mA8M1Y1KUCg/LhOZmaYPNrD9Ms5plsEQb F13A== 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=C/Qeninm4k7erBn5g6OF9DbDV+h2Q7Xz/3gVheNJpxY=; b=gGkW3D1P1g6IhbcTcM2K/Zen32VzTCPJk0X3B1hb/8juo7BoxqHSKx9FVvHUgOveUD TVQP57+SMZSypAbbXModEqrP6XjigkHd/WSE/yZjqgiPetI6jV9QIqUE3QVd7FgvL+Dy g6RFG5lvxDPsuji5ZFlfIvV0BdRdtKStHZHY3B7RJRLI/UhAgeYmtIEp8zfQvDWuOZTX 4mQ+r8ij23kHQmHIdtQLr5jaSS7Wg22kut9P2ldMw5ObR7dgZmE/OUAK6aHKKi3PJrJS 9tgLbVcUERv8n4CGWUYN5rS2luRE9Seykx++iFqCXCBRGE6bzW1O34FibAvp3vHQ+cay RJKA== X-Gm-Message-State: AEkoousn9YfcOjiBUJKLjZTAQbOnpnZTiTyMHq3x0tk1n98/3EEA3a+Y29QQt3aM3vimk1VU7QVnhRjAR78+DA== X-Received: by 10.28.17.138 with SMTP id 132mr4983969wmr.81.1469193868256; Fri, 22 Jul 2016 06:24:28 -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:111749 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