0% found this document useful (0 votes)
1 views1 page

CSC - Conditional Statements in Python

Conditional statements in Python enable decision-making based on conditions, including types such as 'if', 'if-else', 'if...elif...else', 'nested if', 'shorthand if', and 'shorthand if-else'. Each type serves a specific purpose, from executing code based on a single condition to handling multiple conditions and simplifying code. Understanding these statements is essential for effective programming in Python.

Uploaded by

dbf012
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

CSC - Conditional Statements in Python

Conditional statements in Python enable decision-making based on conditions, including types such as 'if', 'if-else', 'if...elif...else', 'nested if', 'shorthand if', and 'shorthand if-else'. Each type serves a specific purpose, from executing code based on a single condition to handling multiple conditions and simplifying code. Understanding these statements is essential for effective programming in Python.

Uploaded by

dbf012
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CONDITIONAL STATEMENTS IN PYTHON:

Conditional statements help computers make decisions when conditions are present. These
statements include an “if” part, which tells the program what to do if the condition is true.
Furthermore, these statements usually include an “else” part, which tells the program what to do
if the condition is false. In Python, there are 6 types of conditional statements used for
decision-making. These include the following: “if” statements, “if-else statements”, “if…Elif…else
statements”, “nested if statements”, “shorthand if statements”, and “shorthand if-else
statements”.

An “if” statement is the most basic of the 6 statements as the code will only be executed if the
condition is present.

An “if-else statement” is used when code needs to be specified when conditions are true or
false.

An “if…Elif…else statement” involves a 3-step process. First, the “if” condition is evaluated. If
the condition is false, then the Elif condition will be evaluated. If the condition is false, then the
“else” statement is executed.

“Nested if statements” allow different “if” statements to be slotted inside one another.

“Shorthand if statements” are used when only one “if” statement needs to be executed inside
the “if” block.

“Shorthand if-else statements” are simplification tools that put both the “if” and “else” statements
in one line of code.

[Link]
s-in-python-for-data-science-beginners/

[Link]
operator

You might also like