Monday 29 July 2019

The else suite


The else suite:
#Find out the output:
for i in range(3):
    print("Hello")
else:
    print("Bye")

"""output:
Hello
Hello
Hello
Bye
>>> """

Example2:
#Find out the output:
for i in range(0):
    print("Hello")
else:
    print("Bye")

"""output:
Bye
>>> """
In python, it is possible to use ‘else’ statement along with loops (for or while), this is called The else suite.

Syntax: for loop

for variable in sequence:
    statement(s)
else:
    statement(s)
syntax: while:
while condition:
    statement(s)
else:
    statement(s)

#searching the data
a=[10,20,30]
n=int(input("enter data to search "))
for i in a:
    if n==i:
        print("Data is found")
        break;
else:
    print("Data is not found")
"""output:
enter data to search 20
Data is found
>>> """


Related Video: https://youtu.be/rUij4z3DVjA

Next Topic: Strings and Characters
Previous Topic: Assessment 8

3 comments:

  1. Sir yesterday python class send you tube sir

    ReplyDelete
    Replies
    1. https://www.youtube.com/watch?v=KfN8GsNZo1E&feature=youtu.be

      Delete

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(&qu...