Entrance Announcement
MICTE 2080
2080 Magh 07
User:Niraj/Teaching-11
Jump to navigation
Jump to search
Teaching lesson plan 11 Subject: Python programming
Date: 26 Jan 2024
Time: 60 minutes
Period: 3rd
Teaching Item: Creating Classes and Objects in Python
Class: Bachelor
Objective:
Students will understand the concepts of classes and objects in Python, learn how to create classes, instantiate objects, define attributes and methods, and utilize inheritance.
Materials Needed:
- Python interpreter or IDE
- Projector
1. Introduction to Classes and Objects (10 mins)
- Define classes and objects:
- Classes are blueprints for creating objects.
- Objects are instances of classes.
- Discuss the importance of classes and objects in programming:
- Encapsulation: bundling data and methods that operate on the data.
- Abstraction: hiding complex implementation details from the user.
- Reusability: creating multiple objects from the same class.
- Inheritance: deriving new classes from existing ones.
2. Creating Classes (15 mins)
- Explain class syntax:
- Keyword
class
followed by the class name. - Class definition block with methods and attributes.
- Keyword
- Demonstrate how to create a simple class:
- Define attributes and methods within the class definition.
- Use the
__init__
method for initialization.
- Discuss naming conventions for classes:
- Class names should follow CamelCase convention.
3. Instantiating Objects (10 mins)
- Introduce object instantiation:
- Syntax:
object_name = ClassName()
- Example:
person = Person()
- Syntax:
- Show how to create multiple objects from the same class:
- Each object has its own set of attributes and methods.
- Discuss the importance of the
self
parameter in methods:self
refers to the instance of the class.
4. Attributes and Methods (15 mins)
- Explain attributes and methods:
- Attributes are variables associated with a class or object.
- Methods are functions defined within a class.
- Demonstrate how to define and access attributes:
- Attributes can be instance attributes or class attributes.
- Use dot notation to access attributes:
object_name.attribute_name
- Show how to define and call methods:
- Methods can take arguments and return values.
- Use dot notation to call methods:
object_name.method_name()
5. Inheritance (10 mins)
- Introduce inheritance:
- Inheritance allows a class to inherit attributes and methods from another class.
- The derived class (subclass) can extend or modify the behavior of the base class (superclass).
- Demonstrate how to create a subclass:
- Syntax:
class SubClassName(BaseClassName):
- Syntax:
- Show how to override methods in the subclass:
- Redefine methods with the same name in the subclass.
6. Exercise (10 mins)
- Provide a simple programming exercise where students:
- Define a base class representing a geometric shape with attributes such as width and height.
- Create subclasses representing specific shapes (e.g., rectangle, circle) with methods to calculate area and perimeter.
7. Conclusion (5 mins)
- Recap the key points covered in the lesson:
- Classes are blueprints for creating objects, while objects are instances of classes.
- Attributes are variables associated with a class or object, and methods are functions defined within a class.
- Inheritance allows classes to inherit attributes and methods from other classes.
- Encourage students to practice creating and using classes and objects in their own projects.