Skip to Content
The Quick Python Book, Third Edition
book

The Quick Python Book, Third Edition

by Naomi Ceder, David Fugate
May 2018
Beginner
472 pages
15h 3m
English
Manning Publications
Content preview from The Quick Python Book, Third Edition

Appendix B. Exercise answers

B.1. Chapter 4

Try this: Variables and expressions

In the Python shell, create some variables. What happens when you try to put spaces, dashes, or other nonalphanumeric characters in the variable name? Play around with a few complex expressions, such as x = 2 + 4 * 5 – 6 / 3. Use parentheses to group the numbers in different ways, and see how that changes the result compared with the original ungrouped expression.

>>> x = 3 >>> y = 3.14 >>> y 3.14 >>> x 3 >>> big var = 12 File "<stdin>", line 1 big var = 12 ^ SyntaxError: invalid syntax >>> big-var Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'big' is not defined >>> big&var Traceback (most recent call last): ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Think Python, 3rd Edition

Think Python, 3rd Edition

Allen Downey
Learn Python Programming - Third Edition

Learn Python Programming - Third Edition

Fabrizio Romano, Heinrich Kruger

Publisher Resources

ISBN: 9781617294037Publisher SupportOtherPublisher WebsiteSupplemental ContentErrata PagePurchase Link