0% found this document useful (0 votes)
30 views13 pages

Cpoopg2l Notes Midterm

The document provides information on flowchart symbols and their uses, arrays and array operations in Python, and object-oriented programming concepts in Python including classes, objects, inheritance, encapsulation, and polymorphism. It defines common flowchart symbols like ovals, rectangles, diamonds, and arrows. It also explains how to define and manipulate arrays and lists in Python using various methods like index, append, extend, insert, remove, pop, reverse, copy, clear, sort. Finally, it introduces object-oriented programming concepts in Python with examples of defining classes and objects, inheritance between classes, encapsulation of attributes and methods, and polymorphism through method overriding in derived classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views13 pages

Cpoopg2l Notes Midterm

The document provides information on flowchart symbols and their uses, arrays and array operations in Python, and object-oriented programming concepts in Python including classes, objects, inheritance, encapsulation, and polymorphism. It defines common flowchart symbols like ovals, rectangles, diamonds, and arrows. It also explains how to define and manipulate arrays and lists in Python using various methods like index, append, extend, insert, remove, pop, reverse, copy, clear, sort. Finally, it introduces object-oriented programming concepts in Python with examples of defining classes and objects, inheritance between classes, encapsulation of attributes and methods, and polymorphism through method overriding in derived classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

LESSON #1: FLOWCHART SYMBOLS

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 & OPERATIONS IN ARRAY

- Array can hold many values


- How big can an array get

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.

32 bit system = 536,870,912 elements

ARRAY OPERATIONS

- Index  Insert  Pop  Remove  Reverse  Append  Extend  Count  Sort  Copy  Clear

PYTHON LIST INDEX

- 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

- the append() method adds an item to the end of the list.


o syntax: list.apppend(item)
- This method takes a single argument.
o Item - an item (number, string, list, etc.) to be added at the end of the list.
- Example:
o Students = ['Vibar','Palebino','Toriano']
o Students.append('jemar')

o print(Students)

PYTHON LIST EXTEND

- 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)

PYTHON LIST INSERT

- 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)

PYTHON LIST POP

- 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)

PYTHON LIST REVERSE

- The reverse() method reverses the elements of the list.


o Syntax: list.reverse()
- Example:
o number = [1,2,3]
o number.reverse()

o print('Reversed list:',number)
PYTHON LIST COPY

- The copy() method returns a shallow copy of the list.


o Syntax: new_list=list.copy()
- Example:
o prime_numbers = [2,3,5]
o numbers = prime_numbers.copy()

o print('copied list:',numbers)

PYTHON LIST CLEAR

- The clear() method removes all items from the list.


o Syntax: list.clear()
- Example:
o prime_numbers = [2,3,5]
o prime_numbers.clear()

o print('list after clear:',prime_numbers)

PYTHON LIST SORT

- 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.

OBJECT – ORIENTED ANALYSIS (OOA)

- 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

OBJECT – ORIENTED DESIGN (OOD)

- 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 CLASS AND OBJECT

- An object is any entity that has attributes and behaviors.


o ATTRIBUTES – name, age, color, etc.
o BEHAVIOR – dancing, singing, etc.
- EXAMPLE:
o class Parrot:
 name = "Yuan"
 age = 32
o parrot1 = Parrot() p
o arrot1.name = "Yuan"
o parrot1.age = 32

o print(f"{parrot1.name} is {parrot1.age} years old")

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))

 def setMaxPrice(self, price):


 self.__maxprice = price

 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

- It makes usage of getter and setters much easier.


- Property() is a built-in function that creates and returns a property object.
o fget is function to get value of the attribute.
o fset is function to set value of the attribute.
o fdel is function to delete the attribute.
o doc is a string (like a comment)
- A property object has three methods, getter(), setter(), and delete().

PYTHON REGEX

- A Regular Expression (RegEx) is a sequence of characters that defines a search pattern.


o Python has a module name re to work with RegEx
- To specify regular expressions, metacharacters are used like ^ or $.
- METACHARACTERS
o Metacharacters are characters that are interpreted in a special way by a RegEx engine
 [] . ^ $ * + ? {} () \ |
o [] (Square Brackets)
 It specifies a set of characters you wish to match.
o . (Period)
 It matches any single character (except newline “\n”)
o ^ (Caret)
 It is used to check if a string starts with a certain character.
o $ (Dollar)
 It is used to check if a string ends with a certain character.
o * (Star)
 It matches zero or more occurrences of the pattern left to it.
o + (Plus)
 It matches one or more occurrences of the pattern left to it.
o ? (Question Mark)
 It matches zero or one occurrences of the pattern left to it.
o {} (Braces)
 Consider this code: {n, m}. This means at least n, and at most m repetitions of the
pattern left to it.
o | (Alternation)
 Vertical bar is used for alternation (or operator)
o () (Group)
 It Is used to group sub-patterns. For example, (a|b|c)xz match any string that
matches either a or b or c followed by xz.
o \ (Backslash)
 It is used to escape various characters including all metacharacters.
- SPECIAL SEQUENCES
o Special sequences make commonly used patterns easier to write.
 \A – Matches if the specified characters are at the start of a string.
 \b – Matches if the specified characters are at the beginning or end of a word.
 \B – Matches if the specified character are not at the beginning or end of a word.
 \d – Matches any decimal digit. Equivalent to [0-9].
 \D – Matches any non-decimal digit. Equivalent to [^0-9]
 \s – Matches where a string contains any whitespace character. Equivalent to
[ \t\n\r\f\v].
 \S – Matches where a string contains any non-whitespace character. Equivalent to
[^ \t\n\r\f\v].
 \w – Matches any alphanumeric character (digits and alphabets). Equivalent to
[a-zA-Z0-9_]. By the way, underscore _ is also considered an alphanumeric character.
 \W – Matches any non-alphanumeric character. ). Equivalent to [^a-zA-Z0-9_].
 \Z – Matches if the specified characters are at the end of a string.
- The re.findall() method returns a list of strings containing all matches.
- The re.split method splits the string where there is a match and returns a list of strings where the
splits have occurred.
- The re.sub() method returns a string where matched occurrences are replaced with the content of
replace variable.
- The re.subn() is similar to re.sub() except it returns a tuple of 2 items containing a new string and
the number of substitutions made.
- The re.search() method take two arguments: a pattern and a string. The method looks for the first
location where the RegEx pattern produces a match with the string.

You might also like