Object Oriented Programming

Object Oriented Programming (OOP)
The examples in this exercise is as outlined bellowing
String Slices
While using the example of the String, a slice is the name given to a substring of the slice. In python, selecting a slice is the same as selecting a character, for example:
>>> s = “James, Kevin, and Mary”
>>> print s[0:5]
James
>>> print s[7:11]
Kevin
>>> print s[17:21]
Mary
While using the String slice, the operator of for example, (n:m)returns to the string from the n-eth character to the m-the character. In this case, it will only include the first but exclude the last. This behavior helps the operator to understand more on the program while imagining on the indices that point to the characters as illustrated in the following diagram:

On this case if the operator omits the first index, the slice will start at the beginning of the string. However, if the operator omits the second index, the slice will go to the end string. For example,
>>> fruit = “banana”
>>> fruit[:3]
‘ban’
>>> fruit[3:]
‘ana’
Optional parameters
In the case of optional parameters, in order to find the second or the third occurrence of the third character in a string, it is advisable to modify the find function. Modifying the find function mean to add a third parameter on for the starting position on the search string. For example;
def find2(strng, ch, start):
index = start
while index < len(strng):
if strng[index] == ch:
return index
index += 1
return -1
On the second example, it is also possible to combine find and find2 while using an optional parameter. For example,
def find(strng, ch, start=0):
index = start
while index < len(strng):
if strng[index] == ch:
return index
index += 1
return -1
#index = start = 0 by default
#while index is less than the length of string:
#if strng[index] equals ch
#return index i.e. location of ch in strng — note return breaks out of loop
#else add 1 to index and continue until index equals the length of sting
#if no match return -1
Adding another optional parameter to find on the program makes it possible for it to search both forward and backward.
def find(strng, ch, start=0, step=1):
index = start
while 0 <= index < len(strng):
if strng[index] == ch:
return index
index += step
return -1
On mathematical expressions, python helps in computing expressions that relate to collections of data and handling mutations. For example, the following expression shows how to compute a mathematical problem on python and get the results.
a = [1, 2]
b = [1, 2]
c = [6, 7, a]
d = [6, 7, a]
e = a + c
f = [c, d]
a.append(5)
c[:1] = []
print a
print b
print c
print d
print e
print f
The following will be the answer of the above problem;
[1, 2, 5]
[1, 2]
[7, [1, 2, 5]
[6, 7, [1, 2, 5]]
[1, 2, 6, 7, [1, 2, 5]]
[[7, [1, 2, 5]], [6, 7, [1, 2, 5]]]

In python programming, a programmer ought o create a point in order to have an own user defined type. In mathematical point, a point refers to two numbers. Both of the numbers are treated collectively and then as a single object. In most of cases, when applying mathematical notations, points in the parenthesis are written while using a comma in separating of the coordinates.

Latest Assignments