|
6 | 6 | "collapsed": true
|
7 | 7 | },
|
8 | 8 | "source": [
|
9 |
| - "#Object Oriented Programming\n", |
| 9 | + "# Object Oriented Programming\n", |
10 | 10 | "\n",
|
11 | 11 | "Object Oriented Programming (OOP) tends to be one of the major obstacles for beginners when they are first starting to learn Python.\n",
|
12 | 12 | "\n",
|
|
70 | 70 | "source": [
|
71 | 71 | "What we will basically be doing in this lecture is exploring how we could create an Object type like a list. We've already learned about how to create functions. So lets explore Objects in general:\n",
|
72 | 72 | "\n",
|
73 |
| - "##Objects\n", |
| 73 | + "## Objects\n", |
74 | 74 | "In Python, *everything is an object*. Remember from previous lectures we can use type() to check the type of object something is:"
|
75 | 75 | ]
|
76 | 76 | },
|
|
189 | 189 | "is called automatically right after the object has been created:\n",
|
190 | 190 | "\n",
|
191 | 191 | " def __init__(self, breed):\n",
|
192 |
| - "Each method in a class definition begins with a reference to the instance object. It is by convention named self. The breed is the argument. The value is passed during the class instantiation.\n", |
| 192 | + "Each attribute in a class definition begins with a reference to the instance object. It is by convention named self. The breed is the argument. The value is passed during the class instantiation.\n", |
193 | 193 | "\n",
|
194 | 194 | " self.breed = breed"
|
195 | 195 | ]
|
|
251 | 251 | "source": [
|
252 | 252 | "Note how we don't have any parenthesis after breed, this is because it is an attribute and doesn't take any arguments.\n",
|
253 | 253 | "\n",
|
254 |
| - "In Python there are also *class object attributes*. These Class Object Attributes are the same for any instance of the class. For example, we could create the attribute *species* for the Dog class. Dogs (regardless of their breed,name, or other atributes will always be mammals. We apply this logic in the following manner:" |
| 254 | + "In Python there are also *class object attributes*. These Class Object Attributes are the same for any instance of the class. For example, we could create the attribute *species* for the Dog class. Dogs (regardless of their breed,name, or other attributes will always be mammals. We apply this logic in the following manner:" |
255 | 255 | ]
|
256 | 256 | },
|
257 | 257 | {
|
|
338 | 338 | "cell_type": "markdown",
|
339 | 339 | "metadata": {},
|
340 | 340 | "source": [
|
341 |
| - "##Methods\n", |
| 341 | + "## Methods\n", |
342 | 342 | "\n",
|
343 | 343 | "Methods are functions defined inside the body of a class. They are used to perform operations with the attributes of our objects. Methods are essential in encapsulation concept of the OOP paradigm. This is essential in dividing responsibilities in programming, especially in large applications.\n",
|
344 | 344 | "\n",
|
345 |
| - "You can basically think of methods as functions acting on an Object that take the Object itself into accoutn through its *self* argument.\n", |
| 345 | + "You can basically think of methods as functions acting on an Object that take the Object itself into account through its *self* argument.\n", |
346 | 346 | "\n",
|
347 | 347 | "Lets go through an example of creating a Circle class:"
|
348 | 348 | ]
|
|
397 | 397 | "source": [
|
398 | 398 | "Great! Notice how we used self. notation to reference attributes of the class within the method calls. Review how the code above works and try creating your own method\n",
|
399 | 399 | "\n",
|
400 |
| - "##Inheritance\n", |
| 400 | + "## Inheritance\n", |
401 | 401 | "\n",
|
402 | 402 | "Inheritance is a way to form new classes using classes that have already been defined. The newly formed classes are called derived classes, the classes that we derive from are called base classes. Important benefits of inheritance are code reuse and reduction of complexity of a program. The derived classes (descendants) override or extend the functionality of base classes (ancestors).\n",
|
403 | 403 | "\n",
|
|
533 | 533 | "cell_type": "markdown",
|
534 | 534 | "metadata": {},
|
535 | 535 | "source": [
|
536 |
| - "##Special Methods\n", |
537 |
| - "Finally lets go over special methods. Classes in Python can implement certain operations with special method names. These methods are not actually called directly but by Python specific language syntac. For example Lets create a Book class:" |
| 536 | + "## Special Methods\n", |
| 537 | + "Finally lets go over special methods. Classes in Python can implement certain operations with special method names. These methods are not actually called directly but by Python specific language syntax. For example Lets create a Book class:" |
538 | 538 | ]
|
539 | 539 | },
|
540 | 540 | {
|
|
612 | 612 | ],
|
613 | 613 | "metadata": {
|
614 | 614 | "kernelspec": {
|
615 |
| - "display_name": "Python 2", |
| 615 | + "display_name": "Python 3", |
616 | 616 | "language": "python",
|
617 |
| - "name": "python2" |
| 617 | + "name": "python3" |
618 | 618 | },
|
619 | 619 | "language_info": {
|
620 | 620 | "codemirror_mode": {
|
621 | 621 | "name": "ipython",
|
622 |
| - "version": 2 |
| 622 | + "version": 3 |
623 | 623 | },
|
624 | 624 | "file_extension": ".py",
|
625 | 625 | "mimetype": "text/x-python",
|
626 | 626 | "name": "python",
|
627 | 627 | "nbconvert_exporter": "python",
|
628 |
| - "pygments_lexer": "ipython2", |
629 |
| - "version": "2.7.10" |
| 628 | + "pygments_lexer": "ipython3", |
| 629 | + "version": "3.5.1" |
630 | 630 | }
|
631 | 631 | },
|
632 | 632 | "nbformat": 4,
|
|
0 commit comments