Learn Python Object-Oriented Programming

inls 560 o bjects n.w
1 / 16
Embed
Share

Dive into the world of Python object-oriented programming by mastering key concepts such as classes, methods, and constructors. Enhance your coding skills with hands-on practice and understand the importance of using classes in client programs.

  • Python
  • Object-Oriented
  • Programming
  • Classes
  • Methods

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. INLS 560 OBJECTS Instructor: Jason Carter

  2. OBJECTS Natural Objects Manufactured Objects

  3. PROGRAM OBJECTS ~ MANUFACTURED OBJECTS Operations accelerate brake Methods Class Program Object execute invoke call accelerate Program Object brake

  4. ANATOMYOFA CLASS The name of the class file should be the name of the class Class Header Class Constructor Class Method

  5. CLASS HEADER The class header is the first line of a class. It declares the name of the class. In our previous example, the name of the class was MyPoint

  6. CLASS CONSTRUCTOR The first method __init__() is a special method, which is called class constructor or initialization method that Python calls when you create a new instance of this class.

  7. SELF IMPLICIT PARAMETER self must be the first parameter to any object method It refers to the object

  8. CLASS METHODS self must be the first parameter to any object method Use self to access the object's fields Other is a point object It has x and y values

  9. USINGA CLASS import class client programs must import the classes they use

  10. USINGA CLASS(CONTD)

  11. USINGA CLASS- OUTPUT

  12. USING CLASS METHODS

  13. USING CLASS METHODS OUTPUT

  14. PRACTICE Write a Fraction class to represent rational numbers like 1/2 and -3/8. The function class should be able to add fractions Create a method named add that takes a fraction as a parameter, adds the two fractions, and returns the sum. Create a method named sum that takes a fraction as a parameter, subtracts the two fractions, and returns the difference. Create a method named multiply that takes a fraction as a parameter, multiplies the two fractions, and returns the product.

  15. CANWEUSE OBJECTS WITH DATABASES? How? Database that held company reviews Table: review Columns: user_id review_id stars date text type business_id votes_funny votes_useful votes_cool

  16. OBJECTS REPRESENT DATABASE TABLE

More Related Content