SlideShare a Scribd company logo
Classes & Objects
AIMAR F. 1906400186
HERNOWO A. 1906400274
HAIDAR L. 1906400135
SAMUEL S. 1906400204
KELAS: DDP1 - C
DOSEN:
FARIZ DARARI
What is a Class
A class is an entity that determines how an object will behave
and what the object will contain. In other words, it is a
blueprint or a set of instruction to build a specific type of
object.
For example in the real world, you often have many objects of
the same kind. Your bicycle is just one of many bicycles in the
world. Using object-oriented terminology, we say that your
bicycle is an instance of the class bicycles.
A class can also contain methods, which are similar to
functions
What is an OBJECT
Objects in OOP are the product of a Class and is an instance of that of said Class.
In the example given before, if you have a bike than your bike is an instance of
the class Bicycle. You can also set attributes for your bicycle. For example, you
can set the condition of your bicycle, set the characteristics of the bike like the
color, the weight, the material, and you can also set an attribute which signifies
that the bike is owned by you.
Making a Class
Class Bicycle (object):
Wheels = 2
def __init__(self, color, weight, materials):
self.color = color
self.weight = weight
self.materials = materials
Making an Object
We can create an object simply by calling the class with the object name
bike1 = Bicycle()
There are two ways to set an attribute the first one is using the method shown in the previous slide. You
can simply set the attribute as you are creating the object
bike1 = Bicycle(“blue”, 5, [“carbon fiber”, “titanium”]
The second way is if you want to add an attribute if the Class doesn’t have an __init__ method you can set
the attribute by writing
bike1.color = “blue”
Methods
Methods are simillar to function. They are both “small programs” that have parameters, perform some
operation and return a value. The difference is that methods are functions tied to a particular object.
Function:
def something(parameter):
pass
Methods:
class Myclass(object):
def something(self,parameter)
...
Methods
Class-Class Relation
Class-Class Relation
Output:
ROG is the best laptop on 2019
ROG has intel i7 processor
Read the comments aloud as you work
through this program to help you
understand what’s happening, then
before you run the program, see if you
can predict the expected output.
THANK YOU
Refrensi:
https://realpython.com/python3-object-oriented-programming/
https://www.journaldev.com/22460/python-str-repr-functions
The Practice Of Computing Using Python (3RD EDITION) by William Punch and Richard Enbody
https://github.com/ialfina/191-ddp1/tree/master/tp4-template
https://www.youtube.com/watch?v=wfcWRAxRVBA

More Related Content

Similar to Classes and object

Lecture 4. mte 407
Lecture 4. mte 407Lecture 4. mte 407
Lecture 4. mte 407
rumanatasnim415
 
OOP in C# Classes and Objects.
OOP in C# Classes and Objects.OOP in C# Classes and Objects.
OOP in C# Classes and Objects.
Abid Kohistani
 
Lecture java continued
Lecture java continuedLecture java continued
Lecture java continued
Kamran Zafar
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
NuurAxmed2
 
Module 3 Class and Object.ppt
Module 3 Class and Object.pptModule 3 Class and Object.ppt
Module 3 Class and Object.ppt
RanjithKumar742256
 
C++ beginner's guide ch08
C++ beginner's guide ch08C++ beginner's guide ch08
C++ beginner's guide ch08Jotham Gadot
 
OOP and C++Classes
OOP and C++ClassesOOP and C++Classes
OOP and C++Classes
MuhammadHuzaifa981023
 
Java and its concepts
Java and its conceptsJava and its concepts
Java and its conceptsaashukaushik
 
Classes_python.pptx
Classes_python.pptxClasses_python.pptx
Classes_python.pptx
RabiyaZhexembayeva
 
Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2
Mahmoud Alfarra
 
Is2215 lecture2 student(2)
Is2215 lecture2 student(2)Is2215 lecture2 student(2)
Is2215 lecture2 student(2)dannygriff1
 
Lecture2.pdf
Lecture2.pdfLecture2.pdf
Lecture2.pdf
SakhilejasonMsibi
 
Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674
Lokesh Kakkar Mobile No. 814-614-5674
 
Core java complete notes - PAID call at +91-814-614-5674
Core java complete notes - PAID call at +91-814-614-5674Core java complete notes - PAID call at +91-814-614-5674
Core java complete notes - PAID call at +91-814-614-5674
WebKrit Infocom
 
Class and Object.pptx
Class and Object.pptxClass and Object.pptx
Class and Object.pptx
Hailsh
 
Lesson 13 object and class
Lesson 13 object and classLesson 13 object and class
Lesson 13 object and class
MLG College of Learning, Inc
 
Unit 1 Part - 2 Class Object.ppt
Unit 1 Part - 2 Class Object.pptUnit 1 Part - 2 Class Object.ppt
Unit 1 Part - 2 Class Object.ppt
DeepVala5
 

Similar to Classes and object (20)

Lecture 4. mte 407
Lecture 4. mte 407Lecture 4. mte 407
Lecture 4. mte 407
 
OOP in C# Classes and Objects.
OOP in C# Classes and Objects.OOP in C# Classes and Objects.
OOP in C# Classes and Objects.
 
Lecture java continued
Lecture java continuedLecture java continued
Lecture java continued
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
 
Module 3 Class and Object.ppt
Module 3 Class and Object.pptModule 3 Class and Object.ppt
Module 3 Class and Object.ppt
 
C++ beginner's guide ch08
C++ beginner's guide ch08C++ beginner's guide ch08
C++ beginner's guide ch08
 
2 oop
2 oop2 oop
2 oop
 
OOP and C++Classes
OOP and C++ClassesOOP and C++Classes
OOP and C++Classes
 
Java and its concepts
Java and its conceptsJava and its concepts
Java and its concepts
 
Classes_python.pptx
Classes_python.pptxClasses_python.pptx
Classes_python.pptx
 
Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2
 
Is2215 lecture2 student(2)
Is2215 lecture2 student(2)Is2215 lecture2 student(2)
Is2215 lecture2 student(2)
 
Lecture2.pdf
Lecture2.pdfLecture2.pdf
Lecture2.pdf
 
Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674
 
Core java complete notes - PAID call at +91-814-614-5674
Core java complete notes - PAID call at +91-814-614-5674Core java complete notes - PAID call at +91-814-614-5674
Core java complete notes - PAID call at +91-814-614-5674
 
Class and Object.pptx
Class and Object.pptxClass and Object.pptx
Class and Object.pptx
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Lesson 13 object and class
Lesson 13 object and classLesson 13 object and class
Lesson 13 object and class
 
Unit 1 Part - 2 Class Object.ppt
Unit 1 Part - 2 Class Object.pptUnit 1 Part - 2 Class Object.ppt
Unit 1 Part - 2 Class Object.ppt
 
java
javajava
java
 

Recently uploaded

STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 

Recently uploaded (20)

STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 

Classes and object

  • 1. Classes & Objects AIMAR F. 1906400186 HERNOWO A. 1906400274 HAIDAR L. 1906400135 SAMUEL S. 1906400204 KELAS: DDP1 - C DOSEN: FARIZ DARARI
  • 2. What is a Class A class is an entity that determines how an object will behave and what the object will contain. In other words, it is a blueprint or a set of instruction to build a specific type of object. For example in the real world, you often have many objects of the same kind. Your bicycle is just one of many bicycles in the world. Using object-oriented terminology, we say that your bicycle is an instance of the class bicycles. A class can also contain methods, which are similar to functions
  • 3. What is an OBJECT Objects in OOP are the product of a Class and is an instance of that of said Class. In the example given before, if you have a bike than your bike is an instance of the class Bicycle. You can also set attributes for your bicycle. For example, you can set the condition of your bicycle, set the characteristics of the bike like the color, the weight, the material, and you can also set an attribute which signifies that the bike is owned by you.
  • 4. Making a Class Class Bicycle (object): Wheels = 2 def __init__(self, color, weight, materials): self.color = color self.weight = weight self.materials = materials
  • 5. Making an Object We can create an object simply by calling the class with the object name bike1 = Bicycle() There are two ways to set an attribute the first one is using the method shown in the previous slide. You can simply set the attribute as you are creating the object bike1 = Bicycle(“blue”, 5, [“carbon fiber”, “titanium”] The second way is if you want to add an attribute if the Class doesn’t have an __init__ method you can set the attribute by writing bike1.color = “blue”
  • 6. Methods Methods are simillar to function. They are both “small programs” that have parameters, perform some operation and return a value. The difference is that methods are functions tied to a particular object. Function: def something(parameter): pass Methods: class Myclass(object): def something(self,parameter) ...
  • 9. Class-Class Relation Output: ROG is the best laptop on 2019 ROG has intel i7 processor Read the comments aloud as you work through this program to help you understand what’s happening, then before you run the program, see if you can predict the expected output.
  • 10. THANK YOU Refrensi: https://realpython.com/python3-object-oriented-programming/ https://www.journaldev.com/22460/python-str-repr-functions The Practice Of Computing Using Python (3RD EDITION) by William Punch and Richard Enbody https://github.com/ialfina/191-ddp1/tree/master/tp4-template https://www.youtube.com/watch?v=wfcWRAxRVBA