PYTHON OBJECTS & CLASSES. What is an object? The abstract idea of anything What is in an object: Attributes Characteristics Represented by internal variables.

Slides:



Advertisements
Similar presentations
Section 6.1 CS 106, Fall The Big Q What do we get by being able to define a class?! Or Do we really need this?!
Advertisements

Object-Oriented Programming
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 28 Classes and Methods 6/17/09 Python Mini-Course: Lesson 28 1.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 26 Classes and Objects 6/16/09 Python Mini-Course: Lesson 26 1.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 9 Classes.
OBJECT-ORIENTED PROGRAMMING. What is an “object”? Abstract entity that contains data and actions Attributes (characteristics) and methods (functions)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 11 Classes and Object- Oriented Programming.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
INFO 206 Lab Exercise 1 Introduction to Classes and Objects 1/18/2012i206 Lab 1 - Exercise1.
Computer Science 111 Fundamentals of Programming I Introduction to Programmer-Defined Classes.
Classes and Objects, Part 1 Victor Norman CS104. Reading Quiz, Q1 A class definition define these two elements. A. attributes and functions B. attributes.
Guide to Programming with Python
REFERENCES: CHAPTER 8 Object-Oriented Programming (OOP) in Python.
Guide to Programming with Python Chapter Nine Working with/Creating Modules.
Centre for Computer Technology ICT115 Object Oriented Design and Programming Week 2 Intro to Classes Richard Salomon and Umesh Patel Centre for Information.
Chapter 10 Classes. Review of basic OOP concepts  Objects: comprised of associated DATA and ACTIONS (methods) which manipulate that data.  Instance:
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Python: Classes By Matt Wufsus. Scopes and Namespaces A namespace is a mapping from names to objects. ◦Examples: the set of built-in names, such as the.
By: Chris Harvey Python Classes. Namespaces A mapping from names to objects Different namespaces have different mappings Namespaces have varying lifetimes.
Chapter 11 Introduction to Classes. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. Code Listing 11.1.
James Tam Classes and Objects You will learn how to define new types of variables.
Classes 1 COMPSCI 105 S Principles of Computer Science.
Chapter 12 Object Oriented Design.  Complements top-down design  Data-centered view of design  Reliable  Cost-effective.
CLASSES Python Workshop. Introduction  Compared with other programming languages, Python’s class mechanism adds classes with a minimum of new syntax.
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.
Chapter Object Oriented Programming (OOP) CSC1310 Fall 2009.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Classes COMPSCI 105 SS 2015 Principles of Computer Science.
Guide to Programming with Python Chapter Eight (Part I) Object Oriented Programming; Classes, constructors, attributes, and methods.
Section 6.1 CS 106 Victor Norman IQ Unknown. The Big Q What do we get by being able to define a class?! Or Do we really need this?!
“everything is an object”. Class Template Code for defining an object Objects are created with NEW keyword (method) Namespace – (disambiguation) Context.
Object Oriented Programming In Python
Classes and Objects, Part 1 Victor Norman CS104. “Records” In Excel, you can create rows that represent individual things, with each column representing.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
PYTHON FUNCTIONS. What you should already know Example: f(x) = 2 * x f(3) = 6 f(3)  using f() 3 is the x input parameter 6 is the output of f(3)
CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of.
Object-Oriented Programming (OOP) in Python References: Chapter 8.
Rajkumar Jayachandran.  Classes for python are not much different than those of other languages  Not much new syntax or semantics  Python classes are.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
CMSC201 Computer Science I for Majors Lecture 25 – Classes
Adapted from slides by Marty Stepp and Stuart Reges
Object-Oriented Programming (OOP) in Python
Topics Procedural and Object-Oriented Programming Classes
Computer Science 111 Fundamentals of Programming I
Lecture VI Objects The OOP Concept Defining Classes Methods
Python Classes By Craig Pennell.
Adapted from slides by Marty Stepp and Stuart Reges
User Defined Classes CS F.
Teach A-Level Computer Science: Object-Oriented Programming in Python
Week 3 Object-based Programming: Classes and Objects
Adapted from slides by Marty Stepp and Stuart Reges
Object Oriented Programming in Python
An Introduction to Object Orientated Programming
Computer Science 111 Fundamentals of Programming I
Objects (again) Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An Introduction.
Python 19 Mr. Husch.
Object-Oriented Programming
CSE 231 Lab 11.
A Level Computer Science Topic 6: Introducing OOP
Programming For Big Data
Python Functions.
Python 19 Mr. Husch.
Migrating to Object-Oriented Programs
Review We've seen that a module is a file that can contain classes as well as its own variables. We've seen that you need to import it to access the code,
Presentation transcript:

PYTHON OBJECTS & CLASSES

What is an object? The abstract idea of anything What is in an object: Attributes Characteristics Represented by internal variables Methods Actions ~ things it can do Represented by internal functions

Car Object What are the attributes of a car? What are the methods of a car?

What is a class definition? class ~ the blueprint/definition of an object User/programmer-defined datatype Class Template: class CLASSNAME: #attributes var = 12 #methods def f(self): return “Hello”

Point Class Example class Point: x = 0 y = 0 def printMe(self): print(self.x, self.y) #self is a keyboard that means “itself” #so it’s own variables can be specified

Creating objects from classes Create an object using this template: varName = ClassName() Access the internal attributes and methods of an object using the dot. p = Point() #creates an instance of Point p.x = 1 #changes the internal variable x p.y = 3 #changes the internal variable y p.printMe() #calls p’s printMe() method

Contact Class Example class Contact: #the __init__ method runs automatically #when an object is created def __init__(self): self.name = "" self.phone = "" def print(self): print(self.name, "-", self.phone) def test(self): self.print()

Contact Class Test Code from contact import * #loads contact.py c = Contact() c.name = "Mr. Bui" c.phone = " " c.test()

Why do we use objects/classes? Encapsulate related variables and functions together Create more organized code Create classes for future use in other programs Modular design Have different people work on different classes at the same time Etc.