Return to Video

They Look So Similar - Programming Foundations with Python

  • 0:00 - 0:03
    Thank you for sharing your answer. Now that
  • 0:03 - 0:06
    we've used classes for the very first time,
  • 0:06 - 0:08
    I want to highlight something that took me
  • 0:08 - 0:10
    a really long time to understand when I
  • 0:10 - 0:13
    was in college. When we wanted to use
  • 0:13 - 0:18
    functions previously, we wrote code like webbrowser.open. But
  • 0:18 - 0:20
    when we wanted to create instances of this
  • 0:20 - 0:24
    class, class turtle, we wrote code that said,
  • 0:24 - 0:27
    turtle.Turtle. Now, look at both of these
  • 0:27 - 0:31
    statements. They look rather similar. It seems
  • 0:31 - 0:36
    like we're calling a function in both of these cases. But something different is
  • 0:36 - 0:39
    happening behind the scene. When we call
  • 0:39 - 0:42
    webbrowser.open, all we are doing is calling
  • 0:42 - 0:45
    a function. No big deal. But when
  • 0:45 - 0:49
    we call turtle.Turtle, the init function defined
  • 0:49 - 0:52
    inside class Turtle, that's the function that gets
  • 0:52 - 0:55
    called. And it creates or initializes space inside
  • 0:55 - 0:57
    memory for a new instance which we called
  • 0:57 - 1:00
    brad. Even though it seems like we called
  • 1:00 - 1:03
    functions in both cases, we called open in
  • 1:03 - 1:06
    the first case and the function init, in
  • 1:06 - 1:09
    the second case. Not all functions are created
  • 1:09 - 1:14
    equal. When we called webbrowser.open, all we did was
  • 1:14 - 1:19
    call a function, but when we called turtle.Turtle, it in turned
  • 1:19 - 1:24
    called the init function which created or initialized space in memory
  • 1:24 - 1:28
    that did not exist before. So, that concludes our first example
  • 1:28 - 1:31
    of how to use classes. Let's look at a few more examples.
Title:
They Look So Similar - Programming Foundations with Python
Description:

more » « less
Video Language:
English
Team:
Udacity
Project:
UD036 - OOP
Duration:
01:32

English subtitles

Revisions Compare revisions