Electron microscopy
 
PythonML
Branching in Python
- Python Automation and Machine Learning for ICs -
- An Online Book -
Python Automation and Machine Learning for ICs                                                           http://www.globalsino.com/ICs/        


Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix

=================================================================================

Branching in Python refers to the ability to execute different blocks of code based on a certain condition. The most common branching statements in Python are if, elif (else if), and else. An example of branching using an if statement is: 

 

 Here,

The if statement checks whether x is greater than 0. If it's true, the code inside the if block is executed. The elif condition and the else block are skipped because once a condition is true, the corresponding block is executed, and the control does not move to the subsequent elif or else blocks. If the if condition were false, then the elif condition would be checked, and if that were false as well, the code inside the else block would be executed.

The elif (else if) statement checks whether x is equal to 0. If the previous condition was false and this one is true, the code inside the elif block is executed. 

If neither the if nor the elif conditions are true, the code inside the else block is executed. 

 

============================================

         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         

 

 

 

 

 



















































 

 

 

 

 

=================================================================================