Skip to content

Instantly share code, notes, and snippets.

@AbheeHub
Created February 13, 2020 13:41
Show Gist options
  • Save AbheeHub/63655746c09b429251dce339ce3636c7 to your computer and use it in GitHub Desktop.
Save AbheeHub/63655746c09b429251dce339ce3636c7 to your computer and use it in GitHub Desktop.
Created on Cognitive Class Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"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": [
"<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": [
"<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": 1,
"metadata": {},
"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": 2,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": 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": 3,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": 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": 4,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": 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": 4,
"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": 5,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute radius\n",
"\n",
"RedCircle.radius"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"'red'"
]
},
"execution_count": 6,
"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": 7,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 7,
"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": 8,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQ0AAAD4CAYAAAD2OrMWAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAbcklEQVR4nO3deZhU1ZnH8e/bTUOMEDcQwYXWEQ2EBxRaXMi4a8ARjHHGgEw0PmMQRxPjmGScLATGjGQcnTiauMuDJBmNk4iCirgNixk10IY1uEGILK04YgAxE0HO/HFu201T1V3VdeueW7d+n+e5T1XXXeq91V1vn3vuvec15xwiIoWqCR2AiFQWJQ0RKYqShogURUlDRIqipCEiRekSOoDO6Nmzp6uvrw8dhkhmNTY2/q9zrleueRWZNOrr61m8eHHoMEQyy8z+kG+eDk9EpChKGiJSFCUNESmKkoaIFEVJQ0SKEkvSMLNpZrbJzFbkmW9mdquZvWFmy8xsaKt5I83s1WjedXHEIyLlE1dLYzowsp35o4D+0TQBuAPAzGqBn0TzBwLj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vMejQ/B84GcvaSJ6iQz3UWcHHUc38CsKX5UCxFOtwPMzvIogphZjYc/z16N/FIS9P530XoXt6Ye4zPx2fQPwNvA3Oj1/sCT7TpOX4N30v+ndBxt9mHA4Bngdejx/3b7gO+Z39pNK1Myz7k+lyBicDE6LkBP4nmLyfPGa7QUwH7cVX0uS8FXgROCh1zjn14AGgCdkTfib+L63ehy8hFpCjVeHgiIiVQ0hCRoihpiEhRlDREpChKGiJSFCUNESmKkoaIFOX/AedMnxeNoYEkAAAAAElFTkSuQmCC\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": 9,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": 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": 10,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": 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": 11,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"100"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute radius\n",
"\n",
"BlueCircle.radius"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"'blue'"
]
},
"execution_count": 12,
"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": 13,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQoAAAD4CAYAAAAU5qhvAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAbmklEQVR4nO3de3xU5Z3H8c9PAjEoBbkH0QWpqGAxlkhtbe22iwqUBlGxuLairkVrrXVt18qlrrbW1brI1lqtsGLVtWLVVWLLRbDetlo1sYAo1yhqTBqwVGkrt8Bv/3jOlDGZZHI5Z55zZn7v12tekzmTnPObZOab5zznnOcRVcUYY1pzgO8CjDHxZ0FhjMnKgsIYk5UFhTEmKwsKY0xWRb4LaKu+ffvqkCFDfJdhTN6qrq5+T1X7ZXouMUExZMgQqqqqfJdhTN4Skbdaes52PYwxWVlQGGOysqAwxmRlQWGMycqCwhiTVShBISILRGSLiKxJW9ZbRJaLyMbg/pC052aIyCYRWS8ip4VRgzEmOmG1KH4BjGuy7GrgSVU9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Kmq1ge7r1u8Ftl2LdXdob9PPu56JHZg3+APmjIZNxMbtPCacl1fG70MHCkiQ0WkG27GuErPNWUlIgeJSI/U18CpuN9/JTAt+LZpxOw904qW6u7Ye8l3j20nenon49JxF9AALEt7bhauN3c9aUc2gHLcH78GuI3gzNS43ID7gFeB1cEftDTba4rjDZgAbAjqneW7njbWfATuaMAq4LVU3UAf4ElgY3Df23etGWp/AKhn/wRb/9Ja3R15L9kp3MaYrPJx18MYEzILCmNMVhYUxpisLCiMMVlZUBhjsrKgMMZkZUFhjMnq/wHBJHawQti6dgAAAABJRU5ErkJggg==\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": 14,
"metadata": {},
"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": 15,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": 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": 16,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute height\n",
"\n",
"SkinnyBlueRectangle.height "
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute width\n",
"\n",
"SkinnyBlueRectangle.width"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"'blue'"
]
},
"execution_count": 18,
"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": 19,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"scrolled": true
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAE4AAAD4CAYAAABCOdB1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAGuklEQVR4nO3dX4hcdxnG8e9jYqitFSuJ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wm725M8ijf13oIFvn9Blurjd3dtrFDrJ1Tp/hBv/mznYOstVnuEG/ubPtg2z1/Mh1lMmj1ZPAl3b6kXRmtncx+dPxW+DE9OvoVtfPSy5TXjmYEs6UcKaEMyWcKeFMCWf6HwezQ1Yzc3TpAAAAAElFTkSuQmCC\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": 20,
"metadata": {},
"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": 21,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute height\n",
"\n",
"FatYellowRectangle.height "
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Print the object attribute width\n",
"\n",
"FatYellowRectangle.width"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"'yellow'"
]
},
"execution_count": 23,
"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": 24,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAABzCAYAAACxdkgEAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAIaklEQVR4nO3dX4gdZx3G8ecxSS+0wdruqrFJXCsixAttWEo1WkoVqbEk6oWk+CegEAoGElA0Uii9rWIRRZRog1WDLdJWQ2mxRVvEi4Turps0catJJMXYNdkqNBUvNPbnxczi6cnMnjnJeWdes98PLDs78549P34z59k5c8551xEhAEC+XtN1AQCApRHUAJA5ghoAMkdQA0DmCGoAyBxBDQCZW5nil46NjcXExESKXw0Al6Xp6ekXI2K8aluSoJ6YmNDU1FSKXw0AlyXbz9dt49IHAGSOoAaAzCW59HFp3HUBAHCR0kzJwRk1AGSOoAaAzBHUAJA5ghoAMkdQA0DmCGoAyBxBDQCZI6gBIHMENQBkjqAGgMw1DmrbK2z/zvajKQsCALzaMGfUuyTNpSoEAFCtUVDbXivpo5J+kLYcAEC/pmfU35T0ZUmvJKwFAFBhYFDbvk3S2YiYHjBuh+0p21MLCwsjKxAAlrsmZ9SbJG2xfUrSA5Jusf2T/kERsTciJiNicny88t9+AQAuwsCgjoivRsTaiJiQtE3SryPi08krAwBI4n3UAJC9of4VV0Q8LenpJJUAACpxRg0AmSOoASBzBDUAZI6gBoDMEdQAkDmCGgAyR1ADQOYIagDIHEENAJkjqAEgcwQ1AGSOoAaAzBHUAJA5ghoAMkdQA0DmCGoAyBxBDQCZI6gBIHMENQBkjqAGgMwR1ACQOYIaADI3MKhtr7P9lO0528ds72qjMABAYWWDMeclfTEiZmyvljRt+8mI+H3i2gAAanBGHRHzETFTLr8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9/8wU2EnPenxQ0smIuNgPOl2SiPiNpL/3rd4q6f5y+X5JH6u4adJpfKvqiognIuJ8+eNBFfPntKqmX0203q9Fti3pk5J+Oqr7a2qJbGjlGOsiqJtMm9r51Kq2JyRdL+lQxeb32j5s+3Hb72qppJD0hO1pFzMV9uu6Z9tU/wDqol+S9KaImJeKB5qkN1aM6bpvn1PxTKjKoH2ews7yksy+mqfxXfbrA5LORMTxmu2t9KsvG1o5xroI6ibTpjaaWjUV21dKekjS7og417d5RsXT+3dL+rakn7dU1qaI2KjiP+18wfZNfds765mLybq2SPpZxeau+tVUl327U9J5Sftrhgza56P2XUlvl/QeSfMqLjP06/KxebuWPptO3q8B2VB7s4p1Q/Wsi6BuMm1qo6lVU7C9SsWO2B8RD/dvj4hzEfGPcvkxSatsj6WuKyJeKL+flfSIiqdTvTrrmYoHxkxEnOnf0FW/SmcWL/+U389WjOmkb7a3S7pN0qeivJDZr8E+H6mIOBMR/4mIVyR9v+b+uurXSkmfkPRg3ZjU/arJhlaOsS6Cusm0qQckfbZ8J8ONkl5afHqRUnkN7D5JcxFxb82YN5fjZPsGFT38W+K6Xmd79eKyihejjvYN66RnpdoznS761eOApO3l8nZJv6gY0/o0vrZvlfQVSVsi4p81Y5rs81HX1fuaxsdr7q+raY8/JOm5iDhdtTF1v5bIhnaOsRSvkDZ4BXWzildNT0q6s1x3h6Q7ymWr+Ie6JyU9K2mypbrer+IpyRFJs+XX5r7adko6puKV24OS3tdCXdeV93e4vO+cevZaFcH7+p51rfdLxR+KeUn/VnEG83lJ10j6laTj5fery7FvkfTYUsdj4rpOqLhmuXiMfa+/rrp9nriuH5fHzhEVQbImh36V63+4eEz1jG2zX3XZ0MoxxicTASBzfDIRADJHUANA5ghqAMgcQQ0AmSOoASBzBDUAZI6gBoDMEdQAkLn/AoCPDaTKyc7EAAAAAElFTkSuQmCC\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",
"language": "python",
"name": "conda-env-python-py"
},
"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.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment