Python else suite

In Python, it is possible to use 'else' statement along with for loop or while loop in the form shown in Table:

for with else while with else

for( var in sequence):

   statements

else:

   statements

while( condition ):

   statements

else:

   statements

The else suite will be always executed irrespective of the statements in the loop are executed or not.

Output:

 Yes

 Yes

 Yes

 Yes

 Yes

 No

It means, the for loop statement is executed and also the else suite is executed.

A Python program to search for an element in the list of elements.


Write a python program to check whether given number is Prime number or not?


Write a python program to list of Prime numbers