Lesson 01_Introduction to Objects and Classes
Lesson 01_Introduction to Objects and Classes
Using Python
ASSESSMENTS
• Quiz- 10%
• Class Participation- 10%
• Midterm Exam-30%
• Final Exam-40%
• Project Viva / Presentation-10%
Class / Lab Rules
• Use of internet is not allowed unless explicitly allowed
• Use of mobiles is not allowed unless explicitly allowed
• No late comings (more than 10 minutes) or early outs
• Discipline should be maintained in teacher’s presence
In case of breach of lab
rules vote for marks
deduction or samosa party?
How to get good grades?
• By putting earnest effort-which brings fruitful results
• By having 75% attendance
• By submitting work on time
• By adhering to lab and class rules
Procedural Programming
• Procedural programming simply contains a series of computational
steps, these steps instruct the computer on how to solve a task in
logical steps.
• A procedural program is typically a list of instructions that execute
one after the other starting from the top of the line.
• Procedural programming is best for simple programs.
Procedural Programming
• Make a Sum function that receives a list of integers as an argument
and returns the sum of integer values stored in a list. Print the
returned total sum at the end.
Procedural Programming
Example
def Sum(sample_list):
total = 0
for x in sample_list:
total += x
return total
list1 = [10, 200, 50, 70]
list2 = [3, 26, 33, 13]
print(Sum(list1))
print(Sum(list2))
Advantages of Procedural
Programming
• Best for general-purpose programming.
• Reusability of the code.
• It is easy to trace the flow of the program.
Disadvantages of Procedural
Programming
• The data is exposed (security issues).
• An object can be defined as a data field that has unique attributes and
behavior.
Object as Real-World Entity
An object has two characteristics:-
• attributes
• behaviors
• Each object instance takes on the properties of the class from which it
was created.
Classes Have Attributes
But Also Behaviors
ATTRIBUTES BEHAVIORS
Name: Open account
Phone: Buy investments
Email: Sell investments
Purchases: Close account
Example:
class Person:
name = "I have no name :("
def sayName (self): When the attributes are accessed
print ("My name is...", self.name) inside the methods of a class they
MUST be preceded by the suffix
“.self”
Class Example
# create a class
class Room:
length = 0.0
breadth = 0.0