Some languages have a special control structure, called switch, or case, or…something like that, that allows you to select from multiple choices of a single variable.…Python doesn't have one.…So, we're going to take a look at one particular strategy where you can do this…very easily within Python, and you'll see that it's not necessarily a weakness in the language;…it's just different way of looking at things.…So, we'll go ahead and make a working copy of switch.py, call it switch-working.…

We'll open our working copy, and we'll start by declaring a dictionary. We'll call it…choices, and we'll just put in a few choices here, one first, two second, three,…and we'll declare a variable and then we'll select based on that variable.…

So, when I save this and run it, you'll see that we have selected one and we…printed out first. And if I change this to say three, save that and run it, it'll save third.…So, here we've been able to very easily select based on a number of choices, and…we could make this a very long list if we wanted to, and we can add things,…

Resume Transcript Auto-Scroll

Author

Released

7/29/2010

Due to its power, simplicity, and complete object model, Python has become the scripting language of choice for many large organizations, including Google, Yahoo, and IBM. In Python 3 Essential Training, Bill Weinman demonstrates how to use Python 3 to create well-designed scripts and maintain existing projects. This course covers the basics of the language syntax and usage, as well as advanced features such as objects, generators, and exceptions. Example projects include a normalized database interface and a complete working CRUD application. Exercise files accompany the course.