English

What is the difference between the else and elif construct of the if statement? - Computer Science (Python)

Advertisements
Advertisements

Question

What is the difference between the else and elif construct of the if statement?

Distinguish Between

Solution

‘Else’ is used along with ‘if’ to define the alternative path if the condition mentioned in the ‘if’ statement is incorrect. This means that only one statement can be evaluated using the if..else statement.

If more than one statements need to be evaluated, the ‘elif’ construct is used. There is no limit on the number of ‘elif’ constructs that should be used in a statement. However, the conditions mentioned in each ‘elif’ construct should be mutually exclusive i.e. if one of the conditions in if..elif is correct it should imply that all the other conditions are false.

shaalaa.com
Introduction to Flow of Control - Selection
  Is there an error in this question or solution?
Chapter 6: Flow of Control - Exercise [Page 139]

APPEARS IN

NCERT Computer Science [English] Class 11
Chapter 6 Flow of Control
Exercise | Q 1. | Page 139
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×