Python Classroom notes 30/Oct/2026

Objects

  • An object has

    • capabilities
    • contents
  • Approach: (Cookie cutter)

    • Class (Mould)
    • object (cookie)
  • I want an object for student as part of attendance project in a school

    • Design a class
    • Using the class create objects
  • Attendence:

    • Student:
      • Contents: (members/attributes)
        • id
        • standard
        • section
        • name
        • school
        • branch
        • city
      • Capabilites: (methods)
        • attend()
        • absent()
  • Lets defined the above student in various languages

  • Python
class Student:
    def __init__(self, id, standard, section, name, school, branch, city):
        self.id = id
        self.standard = standard
        self.section = section
        self.name = name
        self.school = school
        self.branch = branch
        self.city = city

    def attend(self, date):
        pass

    def absent(self, date):
        pass
 ```
* Java
```java
import java.util.Date;

public class Student {
    // Fields
    private String id;
    private String standard;
    private String section;
    private String name;
    private String school;
    private String branch;
    private String city;

    // Constructor initializing all fields
    public Student(String id, String standard, String section, String name, String school, String branch, String city) {
        this.id = id;
        this.standard = standard;
        this.section = section;
        this.name = name;
        this.school = school;
        this.branch = branch;
        this.city = city;
    }

    // Methods
    public void attend(Date date) {
        // Method body
    }

    public void absent(Date date) {
        // Method body
    }
}

  • CSharp
using System;

public class Student
{
    // Properties
    public string Id { get; set; }
    public string Standard { get; set; }
    public string Section { get; set; }
    public string Name { get; set; }
    public string School { get; set; }
    public string Branch { get; set; }
    public string City { get; set; }

    // Constructor initializing all properties
    public Student(string id, string standard, string section, string name, string school, string branch, string city)
    {
        Id = id;
        Standard = standard;
        Section = section;
        Name = name;
        School = school;
        Branch = branch;
        City = city;
    }

    // Methods
    public void Attend(DateTime date)
    {
        // Method body
    }

    public void Absent(DateTime date)
    {
        // Method body
    }
}

  • When it comes to creating objects (objects represent reality). Creating object is referred as instantiation

  • python

a = Student("S001", "10th", "A", "Alice Smith", "Greenwood High", "Science", "Hyderabad")
b = Student("S002", "10th", "B", "Bob Jones", "Greenwood High", "Commerce", "Mumbai")
c = Student("S003", "11th", "A", "Charlie Brown", "Oakridge School", "Arts", "Delhi")

a.attend("30-10-2026")
b.absent("30-10-2026")
c.attend("30-10-2026")
  • Java
Student a = new Student("S001", "10th", "A", "Alice Smith", "Greenwood High", "Science", "Hyderabad");
Student b = new Student("S002", "10th", "B", "Bob Jones", "Greenwood High", "Commerce", "Mumbai");
Student c = new Student("S003", "11th", "A", "Charlie Brown", "Oakridge School", "Arts", "Delhi");

  • Csharp
Student a = new Student("S001", "10th", "A", "Alice Smith", "Greenwood High", "Science", "Hyderabad");
Student b = new Student("S002", "10th", "B", "Bob Jones", "Greenwood High", "Commerce", "Mumbai");
Student c = new Student("S003", "11th", "A", "Charlie Brown", "Oakridge School", "Arts", "Delhi");

By continuous learner

enthusiastic technology learner

Leave a comment