0% found this document useful (0 votes)
10 views8 pages

My Name Is Hellokitty

This document provides an overview of Python classes, explaining their purpose as blueprints for creating objects with bundled data and functionality. It details the structure of classes using examples like Car and Dog, highlighting attributes and behaviors, as well as the importance of the __init__() function and self parameter. Additionally, it includes exercises and homework assignments related to creating Python files for different classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views8 pages

My Name Is Hellokitty

This document provides an overview of Python classes, explaining their purpose as blueprints for creating objects with bundled data and functionality. It details the structure of classes using examples like Car and Dog, highlighting attributes and behaviors, as well as the importance of the __init__() function and self parameter. Additionally, it includes exercises and homework assignments related to creating Python files for different classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

(Python Lesson 12)

Python Class:
• A class is a user-defined blueprint from which objects are created

• Classes provide a means of bundling data and functionality together

• Creating a new class creates a new type of object

• Attributes are the variables that belong to a class

Class Car

Car 1 Attributes Car 3


Color
Model
Car 2 Etc. Car 4
Car
Class
Blueprint on how to create a car
Color
Model
Etc.

Constructor

Car Car Car


Object Object Object

• Red • White • Green


• Ferrari • Tesla • Lamborghini
• Gasoline • Electric • Diesel
Class: Dog
• Attributes: Breed, Color
• Behavior: Noisy, Energetic, Lazy

Using the above class, we can create multiple objects that depict different states and behavior

• Brown
• Curious
• Noisy

• Pink
• Timid
Class Constructor • Noisy

Blank model of dog Factory to give model of dog


Attributes and Behavior

• Blue
• Curious
• Quiet
_ _ init _ _ ( ) Function:

• Used to assign values to object properties

• Contains a collection of instructions

• Runs as soon as an object of a class is created

• Requires a self parameter

Self Parameter:

• Class methods must have an extra first parameter in the method definition

• Python provides the value for this parameter when we call the method

• Minimum need one argument which is the self-parameter


me
• Similar to pointer in C++ and reference in Java

Example:
Exercise:
The exercises done today will be stored in the Lesson 12 folder.

Exercise 1:
Create a new Python file and name it “Car Class.py”.
Exercise 2:
Create a new Python file and name it “Dog Class.py”.
Exercise 3:
Create a new Python file and name it “Turtle Class.py”.
Homework:
Create a new Python file and name it “Homework12.py”.

Write a Python program using a class method to get the expected result as shown below:

Template
Class: Student
Attributes: Gender, Age, Height

To be printed on the output:

You might also like