课程: Programming Concepts for Python
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Match statements
- In addition to the inclusive vegan pizza, I'm also going to order a pizza for myself. The pizza company offers a different pizza deal every day of the week, so I'll make my choice based on the daily special. In this scenario, I need to make a decision based on a single value, the day of the week. One way I can evaluate this series of options is as an if-else-if chain that says, if today is Sunday, then order the spinach pizza, else if today is Monday, order the mushroom pizza, else if today is Tuesday, order the pepperoni pizza, and so on. When my program goes to evaluate the if-else-if chain, it'll evaluate each of those expressions in order. So, let's do that now to pick a pizza. I'll start at the top of the list and work my way down. Is it Sunday? No. Is it Monday? No. Is it Tuesday? No. Is it Wednesday? No. Is it Thursday? No. Is it Friday? No. Is it Saturday? Yes. Today is Saturday, Hawaiian pizza. One…