English feliratok

← What Happens When - Programming Foundations with Python

Beágyazókód kérése
7 Languages

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

  1. So, I will return back to my code. And here, I will attempt to make
  2. an instance of class Movie, in much the same way we did for class Turtle. I
  3. will start by creating a new Python file. I will then Save this file, in the
  4. same folder as my previous Python file. And
  5. I will call this new file entertainment_center.py. So,
  6. here are my two Python files that I have created
  7. thus far. Here's the first one, where I began to
  8. define the class Movie. It was called media.py. And here
  9. is is the new file called entertainment_center.py. Now, here in
  10. this new file, I will say, import media. Now notice
  11. that this is my media file, which is where I
  12. was beginning to define my Movie class and therefore, with
  13. this line of code, I am telling my program, hey here,
  14. I want to use the contents of my previous Python file. Then I will go on to
  15. say toy_story is equal to media.Movie. So, you may
  16. notice here that media is name of my previous
  17. Python file and Movie is the name of
  18. the class that's defined inside that file. One quick
  19. side note here is that I did not have to create a new file. In fact, I could
  20. have written this entire piece of code right here
  21. in my previous file. But it is good practice to
  22. keep the class definition in one file and to call
  23. your class, or to use your class from another file.
  24. Okay, let's continue. So, there is one thing I
  25. want to highlight here. Which is that this line of
  26. code is pretty similar to how we created the turtle
  27. brad. In both cases, I am saying, some module or
  28. file name dot a class name. Now, the next
  29. thing we have to do is figure out exactly what
  30. happens when we run this line of code. One way
  31. to do that is to remember what happened behind the
  32. scenes. When we created the turtle brad. So, let's
  33. investigate that together. Do you remember what happens when we
  34. run the following line of code? Here are some answer
  35. choices. A function named init is called; it initializes or
  36. creates space in memory for the new instance brad. Or, a
  37. function named D-E-L, or del it's called, it deletes the instance brad.
  38. A function named cmp, or compare is called. It compares the instance
  39. brad to angie, or, I don't know. Tell us what you think.