Python With Spyder 11: Objects Part 4 — Inheritance

This is the 11th in a series of videos providing a tutorial on Python 2.7 using Anaconda Python and the Spyder IDE.

This video is the fourth video introducing objects in Python. This video discusses the idea of inheritance.

The source code used in this video can be found here. You can right click on the link and use “Save As” to save the file.

Note: The source code files are plain text files with a “.txt” extention. You will probably want to change the extensions to “.py” after you download them. If you do so, please be aware that if you have Python installed, the file will become executable, so that it will run if you click on it (accidentally or otherwise).

The video is about 26 minutes long.

PWS11-DSSThumb

Next Video: Dictionaries

Video Index: Objects Part 4 — Inheritance

Click on the topics below to jump to that location in the video.

Time Topic
00:00Title Slide
00:26Review example: supermarket products
03:12Define class for milk products
03:23A class with inheritance
03:56Non-dynamic attributes for every instance of a class
04:16Dynamically creating attributes using __init__()
04:41Arguments of __init__() begin with self and include arguments of parent class
05:10Spyder “trick:” split the editor window
06:03Default values for arguments and the value None
08:07Initialization derived from the parent class
09:01Initialization unique to the child class
10:05Using parent class methods
10:59How inheritance works and how names are resolved.
12:08Definition of a second child class inheriting from the Product class
14:48Summary of inheritance so far.
15:18Executing the class (object) definitions
15:34Spyder “trick:” removing the editor window split
15:53Cells in the Spyder editor: The code for each class is in a cell
16:03Execute the code in a cell using cntrl-enter
17:10Create two instances (milk and laudry detergent)
19:58Skipping arguments and using defaults: subsequent variables names must be specified
21:31Spyder: Move console to make it big
21:40Reference values in object attributes
22:25Reference object methods
22:50Error referencing a method
23:10Using dir() to see an object’s attributes and methods
25:20Summary of inheritance in Python

Next Video: Dictionaries

Python With Spyder 10: Objects Part 3 – Private Data and Encapsulation

This is the 10th in a series of videos providing a tutorial on Python 2.7 using Anaconda Python and the Spyder IDE. Click here to go to a “home page” for the video series.

This video is the third of four videos introducing objects in Python. This video discusses private data and encapsulation.

The source code used in this video can be found here. You can right click on the link and use “Save As” to save the file.

Note: The source code files are plain text files with a “.txt” extention. You will probably want to change the extensions to “.py” after you download them. If you do so, please be aware that if you have Python installed, the file will become executable, so that it will run if you click on it (accidentally or otherwise).

The video is about 20 minutes long.

PWS10-DSSThumb

Next Video: Inheritance

Video Index: Private Data and Encapsulation

Click on the topics below to jump to that location in the video.

Time Topic
00:05Introduction
00:41Review of the example
01:22Phone number example of private data
02:10Basic idea of encapsulation
02:42Begin phone number method example
02:58Phone number formats
03:42Private attribute __PhoneNumber
04:53SetPhone() and GetPhone() methods
05:42All methods get self as first argument
07:14“if” statement to test if the phone number is a character string
08:18Use of the “or” keyword in the example
09:37Use of the “in” keyword in the example
10:16Use of the “and” keyword in the example
11:05The line continuation character (“\”)
11:23Use of the “not” keyword in the example
11:45The return statement in the SetPhone() method
11:59Set or create the private attribute __PhoneNumber
13:46Using a “cell” in the editor and cntrl-enter to execute a block of code
14:33Create two instances
14:57Private data cannot be directly accessed
15:15Use the SetPhone() method to set the phone number
16:03Private attribute __PhoneNumber still cannot be directly accessed
16:17Read the phone number with the GetPhone() method
16:45Test the SetPhone() methods with incorrectly formatted phone numbers
18:04Summary of private data in Pythin objects
18:53Summary of Encapsulation
19:12Private methods (functions)

Next Video: Inheritance

Python With Spyder 9: Objects Part 2 – Attributes and Methods and a Few Spyder “Tricks”

This is the 9th in a series of videos providing a tutorial on Python 2.7 using Anaconda Python and the Spyder IDE. Click here to go to a “home page” for the video series.

This video is the second of four videos introducing objects in Python. This video discusses attributes and methods and also demonstrates a few features of the Spyder IDE.

The source code used in this video can be found here. You can right click on the link and use “Save As” to save the file.

Note: The source code files are plain text files with a “.txt” extention. You will probably want to change the extensions to “.py” after you download them. If you do so, please be aware that if you have Python installed, the file will become executable, so that it will run if you click on it (accidentally or otherwise).

The video is about 17 minutes long.

PWS9-DSSThumb

Next Video: Private Data and Encapsulation

Video Index: Attributes and Methods

Click on the topics below to jump to that location in the video.

Time Topic
00:00Title Slide
00:03Location of source code
00:06Review of supermarket product example
00:56Spyder “trick:” Connecting a console to the editor
02:20Spyder “trick:” Code cells in the editor (“#%%”)
03:20Spyder “trick:” Executing a code cell with the toolbar button
04:20Spyder “trick:” Executing a code cell with cntrl-Enter
04:42Spyder “trick:” Executing a code cell with shift-Enter
05:16Most object attributes created dynamically using __init__()
05:37Object attributes do not have to be created dynamically and can be defined for every instance
07:01Terminology: Attribute
07:41Review of __init__()
07:54__init__() is a private method
08:10“Public” methods
09:32Spyder “trick:” Comment and uncomment blocks of code (cntrl-1)
10:20Function definition and indentation for methods
10:41Method example: a Print() function
11:02The first argument of a method is self
11:23Special formatting symbols in strings: “\n” for newline, “\n” for tab
11:49String concatenation (joining) with “+”
12:52Python line continuation with “\” at the end of the line
13:27Convert a number to a striing with the built-in function str()
14:12Run the class definition code for the class Product
14:28Run the code to create two instances of Product
14:38Use the Print() method for the two instances
15:30The built-in function dir()
16:14Summary

Next Video: Private Data and Encapsulation

Python With Spyder 8: Python Objects Part 1

This is the 8th in a series of videos providing a tutorial on Python 2.7 using Anaconda Python and the Spyder IDE. Click here to go to a “home page” for the video series.

This video is the first of four videos on introducing objects in Python. This video covers the basic idea of using the class statement to create objects in Python and then goes on to show how to create objects using the __init__( ) function to dynamically create object attributes.

The source code used in this video can be found here. You can right click on the link and use “Save As” to save the file.

Note: The source code files are plain text files with a “.txt” extention. You will probably want to change the extensions to “.py” after you download them. If you do so, please be aware that if you have Python installed, the file will become executable, so that it will run if you click on it (accidentally or otherwise).

The video is about 23 minutes long.

PWS8-DSSThumb

Next Video: Attributes and Methods

Video Index: Python Objects Part 1

Click on the topics below to jump to that location in the video.

Time Topic
00:00Introduction and Continuation of the Example of Products in a Grcery Store
00:14The data for every product
01:21Create Object for the product Skim Milk
01:39The Python Class statement
01:51The Class Statement Ends in a Colon
02:12Specifying Attributes
04:32The Error Triangle in the Spyder Editor
05:31Executing the Class Statement
06:00Referenceing Object Attributes
07:17The Problem with the Manual Specification of Objects
07:52The Need for an Object Template Approach
08:31Discussion of the Need for Object Constructors
11:05Class Statement for an Object Constructor
11:17The __init__() function to initialize objects
11:47The Reference to Self In the __init__() function
12:41The colon (“:”) at the end of the __init__() function definition
12:58Indentation for the __init()__ function\
13:09Creating Variables using the –init__() function and self
15:07Creating an instance (using the __init__() function and self)
16:18Summary of Object Creation So Far
16:34Executing the Class Statement
16:52Creating an instance (using the __init__() function and self)
17:22Reference Object Attributes
18:08Write the code to creating a second instance
19:34Create the second instance
19:47Reference the Attribues of the Second Instance
20:15Summary of Object Creation So Far
21:37Self is Omitted from the Call to the Object Creator
22:13Summary

Next Video: Attributes and Methods

Python With Spyder 7: The Idea of Objects

This video is the 7th in a series of videos providing a tutorial on Python 2.7 using Anaconda Python and the Spyder IDE. Click here to go to a “home page” for the video series.

This video introduces the idea of objects. No actual Python code is discussed in this video. The objective is only to frame the idea of an object as background for the subsequent videos which present the basics of objects in Python.

The video is about 16 minutes long.

PWS7-DSSThumb

Next Video: Python Objects Part 1

Video Index: The Idea of Objects

Click on the topics below to jump to that location in the video.

Time Topic
00:00Introduction
00:14Example: Products in a Grocery Store
00:24Common Characteristics of All Products
01:56Columns: One View of the Data
03:00Rows as Objects: A Second View of the Data
04:08The Variables for Different Items are Different
06:04Using a Huge Table
07:15Summary of the Most Basic Idea of Objects
07:34More Characteristics of the Concept of Objects: Inheritance, Methods, and Encapsulation
08:02Inheritance
09:47Attributes
11:01Methods
13:14Encapsulation
14:34Summary of Key Object Ideas
15:40Conclusion

Next Video: Python Objects Part 1