Learn other strategies for multiple choices Python 3


show more Understanding other strategies for multiple choices provides you with in-depth training on Developer. Taught by Bill Weinman as part of the Python 3 Essential Training show less
please wait ...

Understanding other strategies for multiple choices

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

Understanding other strategies for multiple choices
Video duration: 2m 38s 6h 36m Beginner

Viewers:

Understanding other strategies for multiple choices provides you with in-depth training on Developer. Taught by Bill Weinman as part of the Python 3 Essential Training

Subjects:
Developer Web
Software:
Python
Author:
please wait ...