You are on page 1of 13

Break statement:

The break is a keyword in python which is used to bring the program control out
of the loop. The break statement breaks the loops one by one, i.e., in the case of
nested loops, it breaks the inner loop first and then proceeds to outer loops. In
other words, we can say that break is used to abort the current execution of the
program and the control goes to the next line after the loop.

The break is commonly used in the cases where we need to break the loop for a
given condition.

The syntax of the break is given below.

#loop statements

break

For Example:

Output:
Continue statement:

The continue statement in Python is used to bring the program control to the
beginning of the loop. The continue statement skips the remaining lines of code
inside the loop and start with the next iteration. It is mainly used for a particular
condition inside the loop so that we can skip some specific code for a particular
condition. The continue statement in Python is used to bring the program control
to the beginning of the loop. The continue statement skips the remaining lines of
code inside the loop and start with the next iteration. It is mainly used for a
particular condition inside the loop so that we can skip some specific code for a
particular condition.

Syntax:

#loop statements

continue

#the code to be skipped

Flow Diagram:
For Example:

Output:
Observe the output of above code, the value 5 is skipped because we have
provided the if condition using with continue statement in while loop. When it
matched with the given condition then control transferred to the beginning of the
while loop and it skipped the value 5 from the code.

Python Strings:

Python string is the collection of the characters surrounded by single quotes,


double quotes, or triple quotes. The computer does not understand the
characters; internally, it stores manipulated character as the combination of the
0's and 1's.

Each character is encoded in the ASCII or Unicode character. So we can say that
Python strings are also called the collection of Unicode characters.

In Python, strings can be created by enclosing the character or the sequence of


characters in the quotes. Python allows us to use single quotes, double quotes, or
triple quotes to create the string.

Syntax:

str = "Hi Python !"

Creating strings in Python:


We can create a string by enclosing the characters in single-quotes or double-
quotes. Python also provides triple-quotes to represent the string, but it is
generally used for multiline string.

Output:

Strings indexing and splitting:

Like other languages, the indexing of the Python strings starts from 0. For
example, The string "HELLO" is indexed as given in the below figure.
For Example:

Output:
As shown in Python, the slice operator [] is used to access the individual
characters of the string. However, we can use the : (colon) operator in Python to
access the substring from the given string. Consider the following example.

Output:

We can do the negative slicing in the string; it starts from the rightmost character,
which is indicated as -1. The second rightmost index indicates -2, and so on.
Consider the following image.
Output:

Reassigning Strings:

The string object doesn't support item assignment i.e., A string can only be
replaced with new string since its content cannot be partially replaced.

For Example:

Output:

Another Example:
Output:

Deleting the string:

We cannot delete or remove the characters from the string. But we can delete
the entire string using the del keyword.

For Example:

Output:

Another Example:

Output:

String Operators:
For Example:

Output:

Escape Sequence:

The list of an escape sequence is given below:


For Example:

Output:

We can ignore the escape sequence from the given string by using the raw string.
We can do this by writing r or R in front of the string. Consider the following
example.

Output:

You might also like