Cpoopg2l Notes Midterm
Cpoopg2l Notes Midterm
FLOWCHART SYMBOLS
- OVAL
o Used to represent start and end of flowchart.
- PARALLELOGRAM
o Used for input and output operation.
- RECTANGLE
o Processing: Used for arithmetic operations and data – manipulations
- DIAMOND
o Decision Making: Used to represent the operation in which there are two/three alternatives,
true and false etc.
- ARROWS
o Flow Line: Used to indicate the flow of logic by connecting symbols.
- CIRCLE
o Page Connector
- OFF PAGE CONNECTOR
o Links a flowchart that is drawn on two or more pages.
- DISPLAY
o Information learning the system.
LESSON #2: ARRAY AND OPERATIONS IN ARRAY
ARRAY
- It is a series or list of values in computer memory, all of which have the same name and data type.
- A subscript, also called an index, is a number that indicates the position of a particular item within an
array.
ARRAY OPERATIONS
- Index Insert Pop Remove Reverse Append Extend Count Sort Copy Clear
- The index() menthod returns the index of the specified element in the list.
o syntax: list.index (element, start, end)
- The list index() method can take a maximum of three arguments:
o Elements - the element to be searched
o Start (optional) - start searching from this index
o End (optional) - search the element up to this index
- Example:
o animals = ['cat','dog','rabbit']
o index = animals.index('rabbit')
o print (index)
PYTHON LIST APPEND
o print(Students)
- The extend() method adds all the elements of an iterable (list, tuple, string etc.) to the end of the list.
o syntax: list1.extend(iterable)
- Here, all the elements of iterable are added to the end of list1.
- Example:
o number1 = [1,9]
o number2 = [2,3,5]
o number1.extend(number2)
o print('number2=',number1)
- The insert() method inserts an element to the list at the specified index.
o Syntax: list.insert(i, elem)
- Example:
o Vowel = ['a','e','i','u']
o Vowel.insert(3,'o')
o print('list',Vowel)
PYTHON LIST REMOVE
- The remover() method removes the first matching element (which is passed as an argument) from the
list.
o Syntax: list.remove(element)
- Example:
o numbers = [2,3,5,7,8,9,11]
o numbers.remove(5)
o print(numbers)
- The list pop() method removes the item at the specific index. The method also returns the removed
item.
o Syntax: list.pop(index)
- Example:
o languages = ['Python','Java','C++','English','C']
o return_value = languages.pop(3)
o print('return value:',return_value)
o print('updated list:',languages)
o print('Reversed list:',number)
PYTHON LIST COPY
o print('copied list:',numbers)
- The sort() methods that sorts the items of a list in ascending or descending orders.
o Syntax: list.sort()
- Example:
o (Ascending)
vowels = ['e','g','u','o','i']
vowels.sort()
print('sorted list(in ascending):',vowels)
o (Descending)
vowels = ['e','g','u','o','i']
vowels.sort(reverse=True)
print('sorted list(in descending):',vowels)
LESSON #3: OBJECT ORIENTED
INTRODUCTION
- A tangible thing that we can sense, feel and manipulate. The earliest objects we interact with are
typically baby toys, wooden blocks, plastic shapes and oversized puzzle pieces are common first
objects. Babies learn quickly that certain objects do certain things: bells ring, buttons are pressed, and
levers are pulled. The definition of an object in software development is not terribly different. Software
objects may not be tangible things that you can pick up, sense, or feel, but they are models of
something that can do certain things and have certain things done to them. Formally, an object is a
collection of data and associated behaviors.
- In the dictionary, oriented means directed toward. So object-oriented means functionally directed
toward modeling objects. This is one of many techniques used for modeling complex systems. It is
defined by describing a collection of interacting objects via their data and behavior. If you've read any
hype, you've probably come across the terms object-oriented analysis, object-oriented design, object-
oriented analysis and design, and object-oriented programming.
- It is the process of looking at a problem, system, or task (that somebody wants to turn into an
application) and identifying the objects and interactions between those objects.
- The analysis stage is all about what needs to be done.
o Review our history
o Apply for jobs
o Browse, compare, and order products
MISNOMER = INACCURATE
- It is the process of converting such requirements into an implementation specification. The designer
must name the objects, define the behaviors, and formally specify which objects can activate specific
behaviors on other objects. The design stage is all about how things should be done.
OBJECT – ORIENTED PROGRAMMING (OOP)
- In Python, object-oriented programming (OOP) It is a programming paradigm that uses objects and
classes in programming. It aims to implement real-world entities like inheritance, polymorphisms,
encapsulation, etc. in the programming, the main concept of OOP's is to bind the data and the
functions that work on that together as a single unit so that no other part of the code can access this
data.
PYTHON INHERITANCE
- Inheritance is a way of creating a new class for using details of an existing class without modifying it.
- EXAMPLE:
o class Animal:
def eat(self):
print("I can eat!")
def sleep(self):
print("I can sleep!")
o class Yuan(Animal):
def bark(self):
print("I can bark! Woof woof!!")
dog1 = Yuan()
dog1.eat()
dog1.sleep()
dog1.bark();
PYTHON ENCAPSULATION
- Encapsulation refers to the bundling of attributes and methods inside a single class.
- It prevents outer classes from accessing and changing attributes and methods of a class. This also
helps to achieve data hiding.
- EXAMPLE:
o class Computer:
def __init__(self):
self.__maxprice = 900
def sell(self):
print("Selling Price: {}".format(self.__maxprice))
c = Computer() c.sell()
c.__maxprice = 1000 c.sell()
c.setMaxPrice(1000) c.sell()
POLYMORPHISM
- It is another important concept of object-oriented programming. It simply means more than one form.
- That is, the same entity (method or operator or object) can perform different operations in different
scenarios.
- EXAMPLE:
o class Polygon:
def render(self):
print("Rendering Polygon...")
o class Square (Polygon):
def render(self):
print("Rendering Square...")
o class Circle(Polygon):
def render(self):
print("Rendering Circle...")
o s1 = Square()
o s1.render()
o c1 = Circle()
o c1.render()
LESSON #4: PYTHON ADVANCED TOPICS
PYTHON ITERATORS
- Methods that iterate collections like lists, tuples, etc. Using iterator method, we can loop through an
object and return its element
- Technically, a Python iterator object must implement two special methods,
o __iter__() and __next__(), collectively called the iterator protocol.
o In Python, we use the next() function to return the next item in the sequence
o The for loop in Python is used to iterate over a sequence of elements, such as a list, tuple, or
string.
- PYTHON INFINITE ITERATORS
o It is an iterator that never ends, meaning that it will continue to produce elements indefinitely.
PYTHON GENERATORS
- It is a function that returns an iterator that produces a sequence of values when iterated over.
- Generators are useful when we want to produce a large sequence of values, but we don’t want to store
all of them in memory at once.
- In python, similar to defining a normal function, we can define a generator function using the def
kewword, but instead of the return statement we use the yield statement.
- PYTHON GENERATOR EXPRESSION
o It is a concise way to create a generator object.
o It is similar to a list comprehension, but instead of creating a list, it creates a generator
object that can be iterated over to produce the values in the generator.
o USE OF PYTHON GENERATORS
Easy to Implement
Memory Efficient
Represent Infinite Stream
Pipelining Generators
PYTHON CLOSURE
- It is a nested function that allows us to access variables of the outer function even after the outer
function is closed.
- Creating a function inside another function is called Nested Function.
- Closures can be used to avoid global values and provide data hiding, and can be an elegant solution for
simple cases with one or few methods.
PYTHON DECORATORS
- It is a design patter that allows you to modify the functionality of a function by wrapping it in another
function.
- The outer function is called the decorator, which takes the original function as an argument and
returns a modified version of it.
PYTHON PROPERTY
PYTHON REGEX