English subtitles

← Connecting Turtle

Get Embed Code
8 Languages

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

  1. Now before we wrap this project up, I want to
  2. take a minute to connect some of the ideas that
  3. we have seen in this lesson thus far. We started
  4. out by creating squares and we wrote a piece of
  5. code that said brad is equal to turtle.Turtle. What we
  6. were really doing behind the scenes there is creating an
  7. object or an instance of the class turtle. What we
  8. could then do with that instance is things like brad.forward.
  9. We then wanted to do things like read contents
  10. from a file on our computer, so we wrote a
  11. piece of code that said quotes equal to open a
  12. file location. What we were really doing behind the scenes
  13. there, is create an object of the type file. We
  14. could then do things with that object like quotes.read. And
  15. when we wanted to access a website on the internet,
  16. we wrote a piece of code that said connection is
  17. equal to urllib.urlopen. Now this piece of
  18. code also returned a file-like object or instance
  19. and we could then do things with
  20. that instance, like connection.read. In all three of
  21. these examples, we created instances or objects
  22. and then we used those objects. Now some
  23. of you may say that in the profanity editor example, all we used were functions.
  24. Functions like open and URL open and that there was no class like we saw in the
  25. previous example with turtle. Well even though on surface
  26. it looks like we did not use any classes
  27. in the profanity editor example, if you look at
  28. how functions like open and urlopen are actually implemented
  29. in Python, we will find that some classes init
  30. like function is being called to return these objects.
  31. Okay, let's look at one more example of how to
  32. use classes. Things will get a lot clearer after that.