Questions And Answers

More Tutorials

Raspberry if else statement

If the expression is true, code block 1 will be executed. If the expression is not true, code block 2 will be executed instead. For example, to take an umbrella if it's raining, and not take an umbrella otherwise.

1 if expression: 
2 code block 1 
3 else: 
4 code block 2

“if……elif……else" statement

This statement is used to judge a variety of conditions. Python will judge whether an expression is true one by one from top to bottom. Once an expression is true, the following code block will be executed. At this point, the remaining conditions will no longer be evaluated and thus not executed, regardless of whether they would have been true. If none of the expressions is true, the code block following “else” will be executed.

1 if expression 1: 
2 code block 1 
3 elif expression 2:
4 code block 2 
5 elif expression 3: 
6 code block 3 
7 ...//other elif statements 
8 else: 
9 code block n


In this page (written and validated by ) you learned about Raspberry if else statement . What's Next? If you are interested in completing Raspberry tutorial, your next topic will be learning about: Raspberry Control LED On and Off with Button.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.