These three are the loop control statements in the python. Using loops in Python automates and repeats the tasks in an efficient manner. But sometimes, there may arise the conditions where we want to exit the loop completely, skip an iteration or ignore that condition. These can be done by loop control statements. Loop control statements changes execution from its normal sequence. When execution leaves a scope, all
automatic objects that were created in that scope are destroyed. Python supports the
following control statements.
How does break, continue and pass work in python?
Break statement: The break statement takes care of terminating the loop in which it is used.
If the break statement is used inside nested loops, the current loop is terminated, and the
flow will continue with the code followed that comes after the loop.
Continue statement: continue statement is opposite to that of break statement, instead of
terminating the loop, it forces to execute the next iteration of the loop. The continue
statement forces the loop to continue or execute the next iteration. When the continue
statement is executed in the loop, the code inside the loop following the continue
statement will be skipped and the next iteration of the loop will begin.
Pass statement: The pass statement in Python is used when a statement is required
syntactically but we do not want any command or code to execute. It is like null operation,
as nothing will happen is it is executed. Pass statement can also be used for writing empty
loops. Pass is also used for empty control statement, function and classes.
Break is a keyword used as a statement in loops (eg- if-else, while, etc)to terminate the current loop or to exit the current loop execution and continues with the next statement/ loop.
while a > 0:
print(‘value :’, a)
a = a -1
if a == 5:
Continue is a keyword used as a statement to give back the control to the beginning of the loop (while, for, etc). It rejects/ eliminates all the other statements that are followed in the current iteration of the loop.
if value == ‘hello’:
Pass is a keyword used as a statement for null operation. It does nothing. This type of statement is used in code blocks where the code is no longer required by the coder.
for a in x:
if value == ‘hello’:
print ‘This is a pass block’
print (‘value :’, a)
Write a Python program to print the documents (syntax, description etc.) of Python built-in function(s).
Python documentation strings or docstrings are string literals that describe what a function does. As the name suggests, it documents the syntax and description and return type of the function. It is associated with python modules, functions, classes and methods. In this case, let’s take built-in functions- abs(), sum().
-output: Return the absolute value of the argument.
Return the sum of a ‘start’ value (default: 0) plus an iterable of numbers
When the iterable is empty,return the start value.
This function is intended specifically for use with numeric values and may
reject non-numeric types.
What is self in Python?
Self is a keyword that is used in class as an instance parameter or a reference parameter. Its main goal is to help access the variables, attributes and methods belonging to that class.
In this article we saw Break, Continue Pass Work and self in In Python so any query about this article then please free to ask.
Intern name who share this task : Vanshika Jain and rekha lodhi
This is the attached link to my github project.
Also see following python arduino base projects