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
Send me today class sir
ReplyDeleteSir yesterday python class send you tube sir
ReplyDeletehttps://www.youtube.com/watch?v=KfN8GsNZo1E&feature=youtu.be
Delete