Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Syntax of if-else Statement | Python if-else Statement
Conditional Statements in Python Clone

Scorri per mostrare il menu

book
Syntax of if-else Statement

Let's briefly discuss the syntax of the if-else construct.

  • The syntax of the if statement remains unchanged;

python
  • Write the else keyword. Note that it is case sensitive, so it is not the same as Else so if you use Else you will get an error because it is not correct;

python
  • Furthermore, you don't need to specify a condition when using else since it inherently implies the opposite condition of the if part;

  • Simply use a colon;

  • Then, proceed with code indentation for the instructions executed within the else-block. These instructions are executed if our condition in the if statement evaluates to False.

Practice Time!

Compito

Swipe to start coding

You have to find the greatest number of three numbers using an if-else statement.

Fill in the blanks.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 2
Siamo spiacenti che qualcosa sia andato storto. Cosa è successo?

Chieda ad AI

expand
ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

book
Syntax of if-else Statement

Let's briefly discuss the syntax of the if-else construct.

  • The syntax of the if statement remains unchanged;

python
  • Write the else keyword. Note that it is case sensitive, so it is not the same as Else so if you use Else you will get an error because it is not correct;

python
  • Furthermore, you don't need to specify a condition when using else since it inherently implies the opposite condition of the if part;

  • Simply use a colon;

  • Then, proceed with code indentation for the instructions executed within the else-block. These instructions are executed if our condition in the if statement evaluates to False.

Practice Time!

Compito

Swipe to start coding

You have to find the greatest number of three numbers using an if-else statement.

Fill in the blanks.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 2
Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Siamo spiacenti che qualcosa sia andato storto. Cosa è successo?
some-alt