Python Branches - If Else Statements Tutorial with Example - APPFICIAL

Pubblicato il: 15 settembre 2021
sul canale di: Appficial
9,162
62

You make decisions everyday, such as what to wear, what to eat, whether to go to school or work, or even to watch this video. You can make similar decisions in your python code using branching.

In programming a branch is computer code that is only executed if a condition is true. For example, if the date is Friday, then run the code to send out weekly paychecks to employees.

To create a branch, you first specify an if statement followed by a boolean expression, or condition that can only be true or false. If the condition is true, the branch executes the indented statements that follow. If the condition is false, you can have an else branch to execute different indented statements.

For example:

if age == 0:
print(’You are a baby’)
else:
print(‘You are not a baby ’)

A code block is a series of statements that are grouped together.  Be sure to properly indent all code belonging to an if statement or an else statement, so python knows which code block belongs to it. Indentations are typically done by one tab, or 3-4 spaces. You should not mix up spaces and tabs for indentation in your program, or it may lead to errors.

A nested if-else is when you have an if-else branch within another if or else

Subscribe to Appficial for more programming videos coming soon. Also, don't forget to click LIKE and comment on the video if it helped you out!


In questa pagina del sito puoi guardare il video online Python Branches - If Else Statements Tutorial with Example - APPFICIAL della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Appficial 15 settembre 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 9,162 volte e gli è piaciuto 62 spettatori. Buona visione!