IF Statement and Conditions
IF Statement and Conditions
Basic Usage
Suppose we want to run different code when certain conditions are (or are not) met. Empty String Example
name = '' print(name)
If we print an empty string we get None. Ideally, we would like to avoid that situation and print something informative instead. We can use an if statement to check if a condition is True or False and then run specific code depending the the result of the condition. Condition statements MUST evaluate to True or False.
name = ''
if name == '': print('Unknown Name')
Above we use the conditional operator == to ask if name is equal to '' (an empty string). Note the colon (:) at the end of the if statement and the indention of the line of code following it.
Below is the list of comparison operators you can use in an if statement.
Operator == != > < >=
0 is True -1 > 0 is False 1 > 1 is False
0 < 1 is True 0 < -1 is False 1 < 1 is False
1 >= 0 is True 1 >= 1 is True -1 >= 0 is False 0 ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- in times of critical need contents from unopened single
- chapter 2 2 conditional statements
- redcap branching logic 2017 201 iths
- three ways to prove if a then b
- creating effective rule statements
- chapter 2 basic ladder logic programming
- conditional statements
- nested ifs if and if or teach ict
- if statement and conditions
- flow chart of if else
Related searches
- if statement based on cell color
- conditional formatting if statement color
- if statement to change cell color
- excel if statement based on color
- excel if statement to change cell color
- conditional if statement excel
- if statement with multiple criteria
- count if statement in tableau
- tableau if statement multiple values
- nested if statement in tableau
- if statement in tableau calculated field
- tableau if statement with dates