Re: learning python. learning defining functions . need help

2016-07-22 Thread Steven D'Aprano
On Sat, 23 Jul 2016 01:21 am, justin walters wrote: > That should illustrate why. This is because simply typing '{}' could be > interpreted as > either a dict or a set. No. {} is always an empty dict. That is a language guarantee. Any programming language where {} is not an empty disk is not

Re: learning python. learning defining functions . need help

2016-07-22 Thread MRAB
On 2016-07-22 16:41, D'Arcy J.M. Cain wrote: On Fri, 22 Jul 2016 08:21:17 -0700 justin walters wrote: You could also replace that line with: if stock is None or type(stock) != dict: Use isinstance(). That handles classes that subclass dict as well. If

Re: learning python. learning defining functions . need help

2016-07-22 Thread D'Arcy J.M. Cain
On Fri, 22 Jul 2016 08:21:17 -0700 justin walters wrote: > You could also replace that line with: > > if stock is None or type(stock) != dict: Use isinstance(). That handles classes that subclass dict as well. -- D'Arcy J.M. Cain System Administrator, Vex.Net

Re: learning python. learning defining functions . need help

2016-07-22 Thread Random832
On Fri, Jul 22, 2016, at 11:21, justin walters wrote: > Try opening the interactive terminal on your command line and type the > following: > > type({}) == dict() > > That should illustrate why. That doesn't illustrate anything relevant at all. The reason this is false is because dict() is

Re: learning python. learning defining functions . need help

2016-07-22 Thread Chris Angelico
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 >

Re: learning python. learning defining functions . need help

2016-07-22 Thread justin walters
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)

Re: learning python. learning defining functions . need help

2016-07-22 Thread Chris Angelico
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

learning python. learning defining functions . need help

2016-07-21 Thread sigmaphine1914
having a little trouble with defining functions. i have a doc called ch5.py and when i was trying the following i had issues " Try It Out: Defining a Function Try saving the following in your file for Chapter 5, ch5.py.def in_fridge(): try: count = fridge[wanted_food]