While loops:
With the while loop we can execute a set of statements as long as a condition is true.
break statement:
It is a loop control statement. Suppose you want to terminate a loop and skip to the next code after the loop; break will help you do that. It is used after the loop statements.
continue statement
With the continue statement we can stop the current iteration, and continue with the next.
for loops:
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
Range() function
The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number.
range(start,stop,step)
start: Optional. An integer number specifying at which position to start. Default is 0
stop: Required. An integer number specifying at which position to stop (not included).
step: Optional. An integer number specifying the incrementation. Default is 1.
STRINGS
A string (str) in Python is a single character or a collection of characters. Strings in python usually represented by double or single quotation.
If we want to print multiple lines of strings, we just have to follow these steps:
len() function
The len() function returns the length of a string:
Indexing
We can access every element in strings by indexing. There are two types of indexing one is positive indexing and another one is negative indexing.
Positive indexing:
Positive indexing starts from 0 and ends at (length of a string -1).
Negative indexing:
Negative indexing starts from -1 and -length of string.
_Strings are immutable. Once a string is created the characters on it can't be changed or deleted. _
Top comments (0)