Skip to content
Advertisement

How does assigning variables to functions work in this python program?

Here is the full python program on pastebin https://pastebin.com/0syTHsJX

,I dont understand how the variable assigned to the function mutable_link() works. if i replace s with mutable_link

for element in reversed(source):
        mutable_link()('push_first', element)
    return mutable_link()

Here is the version that works though.

        s = mutable_link()
        for element in reversed(source):
            s('push_first', element)
        return s

How does assigning the function to variables work and why do i get error when i use just mutable_link() instead.

Advertisement

Answer

I see your code and found that.

  1. In the first case mutable_link() call again and again and then set the contents value to 'empty'.

  2. But in the second case mutable_link() call only once and does not change the contents again and again.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement