
Learn Python Object-Oriented Programming
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.
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
INLS 560 OBJECTS Instructor: Jason Carter
OBJECTS Natural Objects Manufactured Objects
PROGRAM OBJECTS ~ MANUFACTURED OBJECTS Operations accelerate brake Methods Class Program Object execute invoke call accelerate Program Object brake
ANATOMYOFA CLASS The name of the class file should be the name of the class Class Header Class Constructor Class Method
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
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.
SELF IMPLICIT PARAMETER self must be the first parameter to any object method It refers to the object
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
USINGA CLASS import class client programs must import the classes they use
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.
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