[vc_row css_animation=”” row_type=”row” use_row_as_full_screen_section=”no” type=”full_width” angled_section=”no” text_align=”left” background_image_as_pattern=”without_pattern”][vc_column][vc_column_text]

Introduction to if statements in Python

[/vc_column_text][vc_separator type=”normal” up=”1″][vc_column_text css=”.vc_custom_1570723992635{background-color: #f6f6f6 !important;}”]

The if statements in Python is a so-called condition statement. It is a single or multiple statements that are performed depending on whether a logical precondition is fulfilled or not

[/vc_column_text][vc_empty_space height=”20px”][vc_column_text]

HOW TO USE AN IF statement IN PYTHON?

The if statement is used to decide whether or not to perform an operation. If the condition is true, then the operation is performed. If the condition is false, the operation is not performed. The if statement can be combined with several if statements, so-called else-if and else statements.[/vc_column_text][vc_empty_space height=”20px”][vc_column_text]

The if statement is used to decide whether or not to perform an operation

[/vc_column_text][vc_empty_space height=”20px”][vc_column_text]

[/vc_column_text][vc_empty_space height=”20px”][vc_column_text]

In this chapter, we will go through how to combine if-statements with else-if and else-statements to create conditional programming. The flowchart illustrates whether or not an operation should be performed, depending on whether or not the condition in the if statement is met.

[/vc_column_text][vc_empty_space height=”20px”][vc_row_inner row_type=”row” type=”full_width” text_align=”left” css_animation=””][vc_column_inner][vc_single_image image=”19405″ img_size=”medium” alignment=”center” onclick=”link_image” qode_css_animation=””][/vc_column_inner][/vc_row_inner][vc_empty_space height=”20px”][vc_separator type=”normal” thickness=”2″][vc_empty_space height=”10px”][vc_column_text]

DIFFERENT CONDITION STATEMENTS IN PYTHON

[/vc_column_text][vc_empty_space height=”10px”][vc_column_text]

  • if statement  – One or more conditions indicate if one (or more) operations are to be performed

 

  • Elif statement –  The operation / operations inside the elif statement (else if) are performed only if the condition of the if statement is false and the condition of the elif statement is true.

 

  • else – performed when the if and all Elif statements are false.

[/vc_column_text][vc_empty_space height=”20px”][vc_column_text]

[/vc_column_text][vc_empty_space height=”10px”][vc_separator type=”normal”][vc_empty_space height=”10px”][vc_column_text]

LOGICAL COMPARISONS IN PYTHON

It might be a good idea to repeat and remind ourselves of the logical operators we saw in the previous chapter. These will be very useful when using the if statement.[/vc_column_text][vc_empty_space height=”10px”][vc_separator type=”normal”][vc_empty_space height=”20px”][/vc_column][/vc_row][vc_row css_animation=”” row_type=”row” use_row_as_full_screen_section=”no” type=”full_width” angled_section=”no” text_align=”left” background_image_as_pattern=”without_pattern”][vc_column][vc_column_text]

Previous Page    |    Next Page

[/vc_column_text][vc_empty_space][/vc_column][/vc_row]