Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Created on Cognitive Class Labs
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-info\" style=\"margin-top: 20px\">\n",
" <a href=\"https://cocl.us/topNotebooksPython101Coursera\">\n",
" <img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Ad/TopAd.png\" width=\"750\" align=\"center\">\n",
" </a>\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a href=\"https://cognitiveclass.ai/\">\n",
" <img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Ad/CCLog.png\" width=\"200\" align=\"center\">\n",
"</a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h1>Classes and Objects in Python</h1>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<p>\n",
" <strong>Welcome!</strong> \n",
" Objects in programming are like objects in real life. Like life, there are different classes of objects. In this notebook, we will create two classes called Circle and Rectangle. By the end of this notebook, you will have a better idea about :\n",
" <ul>\n",
" <li>what a class is</li>\n",
" <li>what an attribute is</li>\n",
" <li>what a method is</li>\n",
" </ul>\n",
"\n",
" Don’t worry if you don’t get it the first time, as much of the terminology is confusing. Don’t forget to do the practice tests in the notebook.\n",
"</p>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2>Table of Contents</h2>\n",
"<div class=\"alert alert-block alert-info\" style=\"margin-top: 20px\">\n",
" <ul>\n",
" <li>\n",
" <a href=\"#intro\">Introduction to Classes and Objects</a>\n",
" <ul>\n",
" <li><a href=\"create\">Creating a class</a></li>\n",
" <li><a href=\"instance\">Instances of a Class: Objects and Attributes</a></li>\n",
" <li><a href=\"method\">Methods</a></li>\n",
" </ul>\n",
" </li>\n",
" <li><a href=\"creating\">Creating a class</a></li>\n",
" <li><a href=\"circle\">Creating an instance of a class Circle</a></li>\n",
" <li><a href=\"rect\">The Rectangle Class</a></li>\n",
" </ul>\n",
" <p>\n",
" Estimated time needed: <strong>40 min</strong>\n",
" </p>\n",
"</div>\n",
"\n",
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 id=\"intro\">Introduction to Classes and Objects</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Creating a Class</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The first part of creating a class is giving it a name: In this notebook, we will create two classes, Circle and Rectangle. We need to determine all the data that make up that class, and we call that an attribute. Think about this step as creating a blue print that we will use to create objects. In figure 1 we see two classes, circle and rectangle. Each has their attributes, they are variables. The class circle has the attribute radius and color, while the rectangle has the attribute height and width. Let’s use the visual examples of these shapes before we get to the code, as this will help you get accustomed to the vocabulary."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Chapter%203/Images/ClassesClass.png\" width=\"500\" />"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<i>Figure 1: Classes circle and rectangle, and each has their own attributes. The class circle has the attribute radius and colour, the rectangle has the attribute height and width.</i>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"instance\">Instances of a Class: Objects and Attributes</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"An instance of an object is the realisation of a class, and in Figure 2 we see three instances of the class circle. We give each object a name: red circle, yellow circle and green circle. Each object has different attributes, so let's focus on the attribute of colour for each object."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Chapter%203/Images/ClassesObj.png\" width=\"500\" />"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<i>Figure 2: Three instances of the class circle or three objects of type circle.</i>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" The colour attribute for the red circle is the colour red, for the green circle object the colour attribute is green, and for the yellow circle the colour attribute is yellow. \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"method\">Methods</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Methods give you a way to change or interact with the object; they are functions that interact with objects. For example, let’s say we would like to increase the radius by a specified amount of a circle. We can create a method called **add_radius(r)** that increases the radius by **r**. This is shown in figure 3, where after applying the method to the \"orange circle object\", the radius of the object increases accordingly. The “dot” notation means to apply the method to the object, which is essentially applying a function to the information in the object."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Chapter%203/Images/ClassesMethod.png\" width=\"500\" /> "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<i>Figure 3: Applying the method “add_radius” to the object orange circle object.</i>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 id=\"creating\">Creating a Class</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we are going to create a class circle, but first, we are going to import a library to draw the objects: "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Import the library\n",
"\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" The first step in creating your own class is to use the <code>class</code> keyword, then the name of the class as shown in Figure 4. In this course the class parent will always be object: "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Chapter%203/Images/ClassesDefine.png\" width=\"400\" />"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<i>Figure 4: Three instances of the class circle or three objects of type circle.</i>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The next step is a special method called a constructor <code>&#95;&#95;init&#95;&#95;</code>, which is used to initialize the object. The input are data attributes. The term <code>self</code> contains all the attributes in the set. For example the <code>self.color</code> gives the value of the attribute color and <code>self.radius</code> will give you the radius of the object. We also have the method <code>add_radius()</code> with the parameter <code>r</code>, the method adds the value of <code>r</code> to the attribute radius. To access the radius we use the syntax <code>self.radius</code>. The labeled syntax is summarized in Figure 5:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Chapter%203/Images/ClassesCircle.png\" width=\"600\" />"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<i>Figure 5: Labeled syntax of the object circle.</i>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The actual object is shown below. We include the method <code>drawCircle</code> to display the image of a circle. We set the default radius to 3 and the default colour to blue:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create a class Circle\n",
"\n",
"class Circle(object):\n",
" \n",
" # Constructor\n",
" def __init__(self, radius=3, color='blue'):\n",
" self.radius = radius\n",
" self.color = color \n",
" \n",
" # Method\n",
" def add_radius(self, r):\n",
" self.radius = self.radius + r\n",
" return(self.radius)\n",
" \n",
" # Method\n",
" def drawCircle(self):\n",
" plt.gca().add_patch(plt.Circle((0, 0), radius=self.radius, fc=self.color))\n",
" plt.axis('scaled')\n",
" plt.show() "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 id=\"circle\">Creating an instance of a class Circle</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let’s create the object <code>RedCircle</code> of type Circle to do the following:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create an object RedCircle\n",
"\n",
"RedCircle = Circle(10, 'red')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can use the <code>dir</code> command to get a list of the object's methods. Many of them are default Python methods."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"['__class__',\n",
" '__delattr__',\n",
" '__dict__',\n",
" '__dir__',\n",
" '__doc__',\n",
" '__eq__',\n",
" '__format__',\n",
" '__ge__',\n",
" '__getattribute__',\n",
" '__gt__',\n",
" '__hash__',\n",
" '__init__',\n",
" '__init_subclass__',\n",
" '__le__',\n",
" '__lt__',\n",
" '__module__',\n",
" '__ne__',\n",
" '__new__',\n",
" '__reduce__',\n",
" '__reduce_ex__',\n",
" '__repr__',\n",
" '__setattr__',\n",
" '__sizeof__',\n",
" '__str__',\n",
" '__subclasshook__',\n",
" '__weakref__',\n",
" 'add_radius',\n",
" 'color',\n",
" 'drawCircle',\n",
" 'radius']"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Find out the methods can be used on the object RedCircle\n",
"\n",
"dir(RedCircle)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can look at the data attributes of the object: "
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute radius\n",
"\n",
"RedCircle.radius"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'red'"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute color\n",
"\n",
"RedCircle.color"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" We can change the object's data attributes: "
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Set the object attribute radius\n",
"\n",
"RedCircle.radius = 1\n",
"RedCircle.radius"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" We can draw the object by using the method <code>drawCircle()</code>:"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAARAAAAD8CAYAAAC/+/tYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvDW2N/gAAHOVJREFUeJzt3XuYFNWd//H3Vy6DrBdAJCKKqHEV/GlAR1wviTHeICYjrpqg6wUWo8bbRhMfyZqNiQZF8+xiEhUvaFRiVDQSxxUliKi7KsQZwx3l5roShkiCuCoXwTm/P06NtMNcerqr61RXf17P08/MVFdXfXuY/nCquvp8zTmHiEghdghdgIiULwWIiBRMASIiBVOAiEjBFCAiUjAFiIgUTAEiIgVTgIhIwRQgIlKwzqELKETv3r3dgAEDQpchkln19fV/dc7t3t56ZRkgAwYMoK6uLnQZIpllZu/ks54OYUSkYAoQESmYAkRECqYAEZGCKUBEpGCxBIiZ3W9m75nZwlbuNzP7pZktN7P5ZnZYzn0XmNmy6HZBHPWISDLiGoE8AAxr4/7hwAHR7SJgIoCZ9QKuB44EhgLXm1nPmGoSkRKLJUCccy8D69pY5TTgIefNBnqYWV/gFGCGc26dc+59YAZtB5GIpEhSF5L1A97N+XlVtKy15dsxs4vwoxf69+9fmiolf++/Dw0NsHr157+uWQMbN8LWrbBli//66afQqRN07uxvXbpAt27Qpw/suSf07fv5r7vtFvrZSZ6SChBrYZlrY/n2C527B7gHoLq6WjNBJ2HjRpg7F+rr/W3Zsm1BsWlT6fZbVQV77OED5YtfhMMOg8MP91932ql0+5UOSypAVgF75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ayWvLF6x/FuUXYC40k3ynJi2noOZ/cXM+jrnGqIh5XutbGN19HWlmb0IDMEfu4eSz++1aZ1VZtYZ2JW2h9khtPs8nHN/y/nxXuCWBOqKWyyvg0o8hGlxkufANeWqxU8wDa1MNG1mPc2sKvq+N3AMsDixCluWz+8197mdCbzgojN6KdLu82h2rqAGP9dvuakFzo/ejfkH4IOmQ+cOCX22OOYzz6fjk3Uz8BdgerR8T2BaszPQS/H/Y18Xuu5mz2E3YCawLPraK1peDUyKvj8aWIB/h2ABMCZ03a39XoEbgJro+27A48By4I/AfqFrLvB53Awsin7/s4CDQtfcwnN4BGgAtkSviTHAJcAl0f0G3BE9xwW08q5lezddiSoiBavEQxgRiYkCREQKpgARkYIpQESkYAoQESmYAkRECqYAEZGCKUBEpGD/H4AFHidFzXQoAAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Call the method drawCircle\n",
"\n",
"RedCircle.drawCircle()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can increase the radius of the circle by applying the method <code>add_radius()</code>. Let increases the radius by 2 and then by 5: "
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Radius of object: 1\n",
"Radius of object of after applying the method add_radius(2): 3\n",
"Radius of object of after applying the method add_radius(5): 8\n"
]
}
],
"source": [
"# Use method to change the object attribute radius\n",
"\n",
"print('Radius of object:',RedCircle.radius)\n",
"RedCircle.add_radius(2)\n",
"print('Radius of object of after applying the method add_radius(2):',RedCircle.radius)\n",
"RedCircle.add_radius(5)\n",
"print('Radius of object of after applying the method add_radius(5):',RedCircle.radius)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" Let’s create a blue circle. As the default colour is blue, all we have to do is specify what the radius is:"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create a blue circle with a given radius\n",
"\n",
"BlueCircle = Circle(radius=100)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" As before we can access the attributes of the instance of the class by using the dot notation:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"100"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute radius\n",
"\n",
"BlueCircle.radius"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'blue'"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute color\n",
"\n",
"BlueCircle.color"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" We can draw the object by using the method <code>drawCircle()</code>:"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQ0AAAD8CAYAAABtq/EAAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvDW2N/gAAG5JJREFUeJzt3Xu8VWWdx/HPDxBTTFEEA9RABgyvCEex8pqVSAoSaTqVpM1Q4aUc6xXmFJgzajKmM3lJSEZqNDUNRTIR8dJL56Vxjh5QRAZQAuQMijSgSFyf+eNZO/Y5nHP23mfvtZ611/6+X6/92vusfVm/dWB/z/Osy/OYcw4RkWJ1Cl2AiFQXhYaIlEShISIlUWiISEkUGiJSEoWGiJREoSEiJVFoiEhJFBoiUpIuoQsoxoEHHuj69esXugyRTGtoaFjnnOtZ6HVVERr9+vWjvr4+dBkimWZmfy7mdeqeiEhJFBoiUhKFhoiURKEhIiVRaIhISS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XR/TtmNhPf1VprZr2dc01RM/6doEUWr626y/73yWL3pCoHNW7RrxyDn70O2t6etEr177ktZtbNzD6aewx8Hv9vMAsYF71sHNBWCzdt2qp7FnBRdBTlRGBDrhtTtNB7fsvYYzwGn5pbgLXAnLznrsHvwV8CnJW3fCTwP9Fz14Tehhbb82vgVWBh9A/bu9D2pPWW5t9zOzUfhj/SswBYlKsb6AHMA5ZG9weErrWV2n8DNAHbou/EN9qqG989uT36t3mVvCOPxd50RqiIlCSL3RMRiZFCQ0RKotAQkZIoNESkJAoNESmJQkNESqLQEJGSKDREpCT/Dy+kqstFVpjQAAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Call the method drawCircle\n",
"\n",
"BlueCircle.drawCircle()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Compare the x and y axis of the figure to the figure for <code>RedCircle</code>; they are different."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 id=\"rect\">The Rectangle Class</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's create a class rectangle with the attributes of height, width and color. We will only add the method to draw the rectangle object:"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Create a new Rectangle class for creating a rectangle object\n",
"\n",
"class Rectangle(object):\n",
" \n",
" # Constructor\n",
" def __init__(self, width=2, height=3, color='r'):\n",
" self.height = height \n",
" self.width = width\n",
" self.color = color\n",
" \n",
" # Method\n",
" def drawRectangle(self):\n",
" plt.gca().add_patch(plt.Rectangle((0, 0), self.width, self.height ,fc=self.color))\n",
" plt.axis('scaled')\n",
" plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let’s create the object <code>SkinnyBlueRectangle</code> of type Rectangle. Its width will be 2 and height will be 3, and the color will be blue:"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create a new object rectangle\n",
"\n",
"SkinnyBlueRectangle = Rectangle(2, 10, 'blue')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" As before we can access the attributes of the instance of the class by using the dot notation:"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute height\n",
"\n",
"SkinnyBlueRectangle.height "
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute width\n",
"\n",
"SkinnyBlueRectangle.width"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'blue'"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute color\n",
"\n",
"SkinnyBlueRectangle.color"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" We can draw the object:"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAFEAAAD8CAYAAAAPDUgGAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvDW2N/gAABtZJREFUeJzt3V+IpXUdx/H3p9mW0oyM3cJ2nUZBhKUbd4foD3SRCfYH7KKLhMIimKvKQgi78rIuIuoigsUsITHChCSkEksiCGlmM3JbS7PUydUdCTTqYl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PxSB7LAaJaJCIBolokIgGiWiQiAaJaPA/aMI4FW62yxAAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Use the drawRectangle method to draw the shape\n",
"\n",
"SkinnyBlueRectangle.drawRectangle()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let’s create the object <code>FatYellowRectangle</code> of type Rectangle :"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Create a new object rectangle\n",
"\n",
"FatYellowRectangle = Rectangle(20, 5, 'yellow')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" We can access the attributes of the instance of the class by using the dot notation:"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute height\n",
"\n",
"FatYellowRectangle.height "
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute width\n",
"\n",
"FatYellowRectangle.width"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'yellow'"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute color\n",
"\n",
"FatYellowRectangle.color"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" We can draw the object:"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAB2CAYAAADoUHnNAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAL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GoYiaka0V9tdDpa6FJ11a//TwE/X67na2uJbOhlH+sruJtGHBwOyJfa1Dv5c8Abp1IdUJ+aORnY1LD4/RHxUETcExHvnlJJCdwbEZujGolxWJs+7dJaRr+g+ugvgDdn5m6oXnjAmxra9N1vF1O9U2oybpt34dL6FM6NI97299lfHwL2ZOb2Ecun0l9D2dDLPtZXcLcZcbDVqIRdiIjDgVuByzNz39DiLVSnA94DfA+4Yxo1Aadl5mqqH7T4UkScPrS8z/46DDgf+EXD4r76q60+++1K4AXg5hFNxm3z5fYD4B3Ae4HdVKclhvXWX8CFLH203Xl/jcmGkas1zDugPusruNuMOPhSm4hYARzJ/r21m0hEHEq1YW7OzNuGl2fmvsz8Vz19N3BoRKzquq7MfLq+3wvcTvWWdVCfozieC2zJzD3DC/rqr9qexdNF9f3ehja99Ft9geo84NNZnwgd1mKbL6vM3JOZ/8vMF4EfjXi+vvprBfAJYMOoNl3314hs6GUf6yu424w4eCewePX1k8B9o3bw5VKfQ7sB2JaZ145o85bFc+0RcQpVH/6j47reEBFHLE5TXdx6dKjZncDnonIq8NziW7gpGHkk1Ed/DRjchy4CftXQ5tfA2RGxsj41cHY9rzMRcQ7wNeD8zPz3iDZttvly1zV4TeTjI56vr9FCPww8nplPNS3sur+WyIZ+9rEursC2vEq7hurK7E7gynreN6h2ZoDXUb313gH8HjhxCjV9kOotzMPA1vq2BrgEuKRucynwGNXV9AeBD0yhrhPr53uofu7F/hqsK6h+G3Qn8AgwN6Xt+HqqID5yYN7U+4vqH8du4L9URzhfoLom8htge31/dN12Drh+YN2L6/1sB/D5KdS1g+qc5+I+tvjpqbcCdy+1zTuu66f1vvMwVSAdM1xX/fhlr90u66rn/3hxnxpoO83+GpUNvexjfnNSkgrjNyclqTAGtyQVxuCWpMIY3JJUGINbkgpjcEtSYQxuSSqMwS1Jhfk/yJ8hEgZBDtYAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Use the drawRectangle method to draw the shape\n",
"\n",
"FatYellowRectangle.drawRectangle()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>The last exercise!</h2>\n",
"<p>Congratulations, you have completed your first lesson and hands-on lab in Python. However, there is one more thing you need to do. The Data Science community encourages sharing work. The best way to share and showcase your work is to share it on GitHub. By sharing your notebook on GitHub you are not only building your reputation with fellow data scientists, but you can also show it off when applying for a job. Even though this was your first piece of work, it is never too early to start building good habits. So, please read and follow <a href=\"https://cognitiveclass.ai/blog/data-scientists-stand-out-by-sharing-your-notebooks/\" target=\"_blank\">this article</a> to learn how to share your work.\n",
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-info\" style=\"margin-top: 20px\">\n",
"<h2>Get IBM Watson Studio free of charge!</h2>\n",
" <p><a href=\"https://cocl.us/bottemNotebooksPython101Coursera\"><img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Ad/BottomAd.png\" width=\"750\" align=\"center\"></a></p>\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>About the Authors:</h3> \n",
"<p><a href=\"https://www.linkedin.com/in/joseph-s-50398b136/\" target=\"_blank\">Joseph Santarcangelo</a> is a Data Scientist at IBM, and holds a PhD in Electrical Engineering. His research focused on using Machine Learning, Signal Processing, and Computer Vision to determine how videos impact human cognition. Joseph has been working for IBM since he completed his PhD.</p>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Other contributors: <a href=\"www.linkedin.com/in/jiahui-mavis-zhou-a4537814a\">Mavis Zhou</a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<p>Copyright &copy; 2018 IBM Developer Skills Network. This notebook and its source code are released under the terms of the <a href=\"https://cognitiveclass.ai/mit-license/\">MIT License</a>.</p>"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.