Saw repeatedly such functions where arguments and some kind of the pointer are transferred.

For example: add('Иван', 15, table)

Ivan is a string data type, 15 is an integer data type, but there is also an argument table , which performs the function of some kind of pointer, or key.

What is the correct name for this parameter? Where can I read about this functionality?

  • it looks like table is just the name of a variable - Grundy
  • @Grundy, no, this is true or false. For example add ('Ivan', 15) we add the name Ivan and 15, if we add log to the add function ('Ivan', 15, log), for example, the program will also make a log of this function. - BilliS Play
  • Show the definition of the function add - Grundy
  • @Grundy, this is just a fictional function. Well, using the example of Tkinter widget.bind("z", callback) (keystroke event on the keyboard), the callback is called every time the "z" key is pressed. I apologize if I do not understand something or do not express myself correctly. - BilliS Play
  • 2
    Add a specific example to the question - Grundy

1 answer 1

No name, it's just a variable. Another thing is that a variable can be absolutely any object, and with some objects you can do quite interesting things.

For example, in python, a function is also an object. Therefore, we can pass a function as a function argument:

 def foo(a): print('Функция foo сработала с аргументом ' + str(a)) def bar(number, function): function(number) bar(7, foo) # Напечатает: Функция foo сработала с аргументом 7 

Or you can pass as an argument any changeable object, the function will do something with this object, and the changed state will be at this object outside the function as well. Perhaps this is exactly what you mean by the words "some kind of pointer":

 def egg(spam): # Изменяю переданный объект spam.append('cheese') my_list = [] egg(my_list) print(my_list) # Напечатает: ['cheese'] 

And in the example you specified with the tkinter, the bind method seems to simply save a pair (буква, функция) to some dictionary, and every time the widget captures keystrokes, it checks if there is such a letter in its dictionary, and if is, calls the appropriate function.

In all this there is no special functionality. This is simply a consequence of the fact that in python absolutely everything is an object that can be passed as an argument. Both functions are objects, and classes are objects, and everything else is also objects.