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): ...
Get The Quick Python Book, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.