Hello dear readers! Welcome back to another edition of our tutorial on Python. In this tutorial guide, we are going to be discussing about decision making in Python.
Decision making is the prediction of conditions during the execution of the program and also specifying the actions taken according to each of the conditions.
The Python programming decision structure does evaluates different expressions which produces TRUE or FALSE as an outcome. You need to determine which action to take and which statements that is to be executed if the outcome is TRUE or FALSE.
Following below is the general form of a typical decision making structure found in most of the programming languages -
Decision making is the prediction of conditions during the execution of the program and also specifying the actions taken according to each of the conditions.
The Python programming decision structure does evaluates different expressions which produces TRUE or FALSE as an outcome. You need to determine which action to take and which statements that is to be executed if the outcome is TRUE or FALSE.
Following below is the general form of a typical decision making structure found in most of the programming languages -
RECOMMENDED: Python Operators
Python assumes any non-zero and non-null values as TRUE, and if it is either zero or null then it is then assumed as FALSE value.
The Python language provides the following types of decision making statements.
The Python language provides the following types of decision making statements.
Sr.No. | Statement & Description |
---|---|
1 | if statements
An if statement consists of a boolean expression followed by one or more statements.
|
2 | if...else statements
An if statement can be followed by an optional else statement, which executes when the boolean expression is FALSE.
|
3 | nested if statements
You can use one if or else ifstatement inside another if or else if statement(s).
|
In our subsequent tutorials, we are going to be discussing about each of these statements that we have listed out above.
RECOMMENDED POST: Python Basic Syntax Tutorial
Single Statement Suites
If the suite of an if clause consists only of a single line, then it may go on the same line with the header statement.
Example
Below is an example of one-line if clause -
#!/usr/bin/python var = 500 if ( var == 100 ) : print "Value of expression is 500" print "Welcome to Web design tutorialz!"
Output
Below is the output of the above example -
Value of expression is 500 Welcome to Web design tutorialz!
RECOMMENDED: Python Variables and Data Types
Alright guys! This is where we are rounding up for this tutorial. In our next tutorial, we will be discussing about the Python If Statement.
Do feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.
Do feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.