English subtitles

← They Look So Similar - Programming Foundations with Python

Get Embed Code
6 Languages

Showing Revision 4 created 05/24/2016 by Udacity Robot.

  1. Thank you for sharing your answer. Now that
  2. we've used classes for the very first time,
  3. I want to highlight something that took me
  4. a really long time to understand when I
  5. was in college. When we wanted to use
  6. functions previously, we wrote code like webbrowser.open. But
  7. when we wanted to create instances of this
  8. class, class turtle, we wrote code that said,
  9. turtle.Turtle. Now, look at both of these
  10. statements. They look rather similar. It seems
  11. like we're calling a function in both of these cases. But something different is
  12. happening behind the scene. When we call
  13. webbrowser.open, all we are doing is calling
  14. a function. No big deal. But when
  15. we call turtle.Turtle, the init function defined
  16. inside class Turtle, that's the function that gets
  17. called. And it creates or initializes space inside
  18. memory for a new instance which we called
  19. brad. Even though it seems like we called
  20. functions in both cases, we called open in
  21. the first case and the function init, in
  22. the second case. Not all functions are created
  23. equal. When we called webbrowser.open, all we did was
  24. call a function, but when we called turtle.Turtle, it in turned
  25. called the init function which created or initialized space in memory
  26. that did not exist before. So, that concludes our first example
  27. of how to use classes. Let's look at a few more examples.