Can someone explain to me ex38?

  1. Python sees you mentioned mystuff and looks up that variable. It might have to look backward
    to see if you created it with =, if it is a function argument, or if it’s a global variable. Either way
    it has to find the mystuff first.
  2. Once it finds mystuff it reads the . (period) operator and starts to look at variables that are a
    part of mystuff. Since mystuff is a list, it knows that mystuff has a bunch of functions.
  3. It then hits append and compares the name to all the names that mystuff says it owns. If append
    is in there (it is), then Python grabs that to use.
  4. Next Python sees the ( (parenthesis) and realizes, ”Oh hey, this should be a function.” At this
    point it calls (runs, executes) the function just like normally, but instead it calls the function with
    an extra argument.
  5. That extra argument is … mystuff! I know, weird, right? But that’s how Python works, so it’s
    best to just remember it and assume that’s the result. What happens, at the end of all this, is
    a function call that looks like: append(mystuff, ‘hello’) instead of what you read, which is
    mystuff.append(‘hello’).

Here’s what I don’t understand:
2.) Is the variables part of mystuff the items in it?

3.) Why when it hits append, it compares to all the names that mystuff says it owns instead of carrying out the append function. Moreover, is the things that mystuff owns, the items inside the list?

4.) What does it mean by “calls the function with an extra argument”

5.) Isn’t mystuff what it read in the first place/looked up? Then what happens to the string ‘hello’? And finally, why is mystuff.append(‘hello’) now append(mystuff, ‘hello’), I thought that mystuff was read first?

Thanks

Hi @Potatodef, sorry for the late response!

No. In this case “the variables part of mystuff” refers to things like append, pop, etc. The methods (and attributes) attached to this particular object.

At this point, “append” is just a symbol or a name for something. Python hasn’t made the connection between the symbol and the function it refers to yet. That’s what happens in this step. Dot notation tells Python “look for something called append in the object before the dot.”

You write mystuff.append(x). One argument x. Python transforms this into List.append(mystuff, x), where List.append is a function defined in the class List that you can access via every list instance, like we’re doing here with mystuff. The additional argument is the list instance that the function should operate on, mystuff.

Does that help?

@florian thanks a lot for the help!!