Exercise 32. Scanners

My first book, Learn Python 3 the Hard Way, very casually covered scanners in Exercise 48, but now we’re going to get more formal. I’ll explain the concept behind scanning text, how that relates to regular expressions, and how you can create a little scanner for a tiny piece of Python code.

Let’s use the following Python code as an example to start the discussion:

def hello(x, y):     print(x + y) hello(10, 20)

You’ve been training in Python for a while, so your brain most likely can read this code quickly, but do you really understand what it is? When I (or someone else) taught you Python I had you memorize all the “symbols.” The def and () characters are each symbols, but there needs to be a way for Python to process ...

Get Learn More Python 3 the Hard Way: The Next Step for New Python Programmers 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.