Recent Changes - Search:

Basics

Languages

Tools

OS

Resources

PmWiki

pmwiki.org

edit SideBar

IfStatements

If statements are a mainstay of programming, allowing you to check pretty much anything with the right conditions. In python, they are written as:

if condition:
    code to execute when condition is true
elif condition2:
    code to execute when condition2 is true
else:
    code to execute when none of the above conditions are true

In simple cases when assigning values to a variable depending on the situation, this can all be written in one line:

var = value1 if condition else value2

Edit - History - Print - Recent Changes - Search
Page last modified on June 01, 2022, at 10:58 AM