- Python 3 - Exceptions
- Python 3 - Files I/O
- Python 3 - Modules
- Python 3 - Functions
- Python 3 - Date & Time
- Python 3 - Dictionary
- Python 3 - Tuples
- Python 3 - Lists
- Python 3 - Strings
- Python 3 - Numbers
- Python 3 - Loops
- Python 3 - Decision Making
- Python 3 - Basic Operators
- Python 3 - Variable Types
- Python 3 - Basic Syntax
- Python 3 - Environment Setup
- Python 3 - Overview
- What is New in Python 3
- Python 3 - Home
Python 3 Advanced Tutorial
- Python 3 - Further Extensions
- Python 3 - GUI Programming
- Python 3 - XML Processing
- Python 3 - Multithreading
- Python 3 - Sending Email
- Python 3 - Networking
- Python 3 - Database Access
- Python 3 - CGI Programming
- Python 3 - Reg Expressions
- Python 3 - Classes/Objects
Python 3 Useful Resources
- Python 3 - Discussion
- Python 3 - Useful Resources
- Python 3 - Tools/Utilities
- Python 3 - Quick Guide
- Python 3 - Questions and Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Python 3 - Decision Making
Decision-making is the anticipation of conditions occurring during the execution of a program and specified actions taken according to the conditions.
Decision structures evaluate multiple expressions, which produce TRUE or FALSE as the outcome. You need to determine which action to take and which statements to execute if the outcome is TRUE or FALSE otherwise.
Following is the general form of a typical decision making structure found in most of the programming languages −
Python programming language assumes any non-zero and non-null values as TRUE, and any zero or null values as FALSE value.
Python programming language provides the following types of decision-making statements.
Sr.No. | Statement & Description |
---|---|
1 | An if statement consists of a boolean expression followed by one or more statements. |
2 | An if statement can be followed by an optional else statement, which executes when the boolean expression is FALSE. |
3 | You can use one if or else if statement inside another if or else if statement(s). |
Let us go through each decision-making statement quickly.
Single Statement Suites
If the suite of an if clause consists only of a single pne, it may go on the same pne as the header statement.
Example
Here is an example of a one-pne if clause −
#!/usr/bin/python3 var = 100 if ( var == 100 ) : print ("Value of expression is 100") print ("Good bye!")
Output
When the above code is executed, it produces the following result −
Value of expression is 100 Good bye!Advertisements