Python Revision Tour 1
Python Revision Tour 1
Revision Notes
Statements are the instructions given to the computer to perform any kind of action.
Python statements can be one of these types: empty statement, single statement and
compound statement.
Every compound statement of Python has a header and an indented body below the
header. Some examples of compound statements are: functions, if statement, while
statement etc.
Python provides one selection statement if in many forms - if..else and if..elif..else.
The statements that allow a set of instructions to be performed repeatedly are iteration
statements.
Python provides two looping constructs - for and while. The for loop is a counting loop
and while is a conditional loop.
The while loop is an entry-controlled loop as it has a control over entry in the loop in the
form of test condition.
Loops in Python can have else clause too. The else clause of a loop is executed in the
end of the loop only when loop terminates normally.
The break statement can terminate a loop immediately and the control passes over to
the statement following the statement containing break.
In nested loops, a break statement terminates the very loop it appears in.
The continue statement abandons the current iteration of the loop by skipping over the
rest of the statements in the loop-body. It immediately transfers control to the beginning
of the next iteration of the loop.
In Python, indices begin 0 onwards in the forward direction up to length-1 and -1, -2, ....up
to - length in the backward direction. This is called two-way indexing.
The string slice refers to a part of the string s[start:end) is the element beginning at start
and extending up to but not including end.
Lists are mutable sequences of Python i.e., you can change elements of a list in place.
Lists index their elements just like strings, i.e., two way indexing.
Lists are similar to strings in many ways like indexing, slicing and accessing individual
element but they are different in the sense that Lists are mutable while strings are not.
Membership operator in tells if an element is present in the sequence or not and not in
does the opposite.
L[start:stop] creates a list slice out of List L with elements falling between indexes start
and stop, not including stop.
Tuples are immutable sequences of Python i.e., you cannot change the element of a
tuple in place.
Tuples index their elements just like strings or lists, i.e., two way indexing.
Tuples are stored in memory exactly like strings, except that because some of their
objects are larger than others, they store a reference at each index instead of single
character as in strings.
T[start:stop] creates a tuple slice out of tuple T with elements falling between indexes
start and stop, not including stop.
Dictionaries are mutable with elements in the form of a key:value pair that associate
keys to values.
In Python dictionaries, the elements (key:value pairs) are unordered; one cannot access
element as per specific order.
In Dictionaries, the updation and addition of elements are similar in syntax. But for
addition, the key must not exist in the dictionary and for updation, the key must exist in
the dictionary.
In bubble sort, the adjoining values are compared and exchanged if they are not in proper
order. This process is repeated until the entire array is sorted.