课程: Programming Concepts for Python

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

If-else statements

If-else statements

- Every programming language has some form of the classical if-then-else statement. Each language may use different words and syntax for it, but they all accomplish the same thing, which is to allow for conditional execution. The program is able to choose which code it executes based on some condition, such as the value of a variable, whether or not a file is empty or any number of things. One of the first things that every new programmer learns is how to use an if-else statement, which allows your program to take one of two possible paths. If some condition, do this, otherwise, do that. Things can get a bit more confusing when we start building complex conditional statements that have more than just two possible choices. The way we as humans make decisions among several different options is different than a computer. Computers can only make binary decisions, which means it can only decide between two things at a time.…

内容