effectivepython icon indicating copy to clipboard operation
effectivepython copied to clipboard

Item #10: Incorrect assignment expression

Open Leefir opened this issue 4 years ago • 1 comments

Page 39, Item 10, line 7 from bottom

to_enjoy‘= 'Nothing'

should be written as

to_enjoy = 'Nothing'

It is in the second code snippet on Page 39:

count = fresh_fruit.get('banana', 0)
if count >= 2:
    pieces = slice_bananas(count)
    to_enjoy = make_smoothies(pieces)
else:
    count = fresh_fruit.get('apple', 0)
    if count >= 4:
        to_enjoy = make_cider(count)
    else:
        count = fresh_fruit.get('lemon', 0)
        if count:
            to_enjoy = make_lemonage(count)
        else:
            to_enjoy‘= 'Nothing'

Leefir avatar Feb 01 '21 13:02 Leefir

I also have this error in my hard copy of Effective Python (Second Edition). The code here: https://github.com/bslatkin/effectivepython/blob/master/example_code/item_10.py is correct. I have found the GitHub code to be well-done and instructive. Slatkin makes an effort to write the code so that it will run by building up any dummy functions, using exception handling where it would make the text version less readable, and occasionally adding more examples.

aambrioso1 avatar May 30 '21 15:05 aambrioso1

Thank you for the report! The extraneous ` was a typo.

bslatkin avatar May 31 '24 23:05 bslatkin

Will be addressed in post-production

bslatkin avatar Jun 02 '24 05:06 bslatkin