Python Branches - If Else Statements Tutorial with Example - APPFICIAL

Veröffentlicht am: 15 September 2021
auf dem Kanal: 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!


Auf dieser Seite können Sie das Online-Video Python Branches - If Else Statements Tutorial with Example - APPFICIAL mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Appficial 15 September 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 9,162 Mal angesehen und es wurde von 62 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!