O'Reilly logo

Learn More Python 3 the Hard Way: The Next Step for New Python Programmers by Zed A. Shaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required