3

This function:

hand_p = ''

def hand_player(card_variable):
    global hand_p
    hand_p = hand_p + str(card_variable)
    return hand_p

is returning something like function hand_player at 0x7f37c058d378.

Why is this happening?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Sondr
  • 35
  • 3
  • 4
    You might just be referencing the function like this `hand_player` but you have to call the function to get the output like so `hand_player()` – techytushar Oct 12 '19 at 15:19
  • 1
    That's just how Python represents the function object. It's not being *returned*; if you see that, you're not *calling* the function. But without a [mcve] that's all we can tell you. – jonrsharpe Oct 12 '19 at 15:31

2 Answers2

2

You haven't called the function anywhere in your code. If you wanted to pass an argument of 'a' you could call it as follows:

hand_p = ''

def hand_player(card_variable):
    global hand_p
    hand_p = hand_p + str(card_variable)
    return hand_p

print(hand_player('a'))
1

You have assigned (or are assigning somewhere else in your code, since it is not clear from your posted code where exactly you are doing the assignment) the function to a variable. This is something like function pointers of c.

Given your posted code, you are probably writing somewhere:

variable = hand_player

and you are effectively storing the "entire function" to a variable. Of course, this is not exactly what is happening, only the pointer to the address in memory, where the code of the function is located, is stored to your variable.

Technically, thereafter, you can call your function through your stored variable in the same way, i.e.

variable(some_card)

See this question for a bit more information.

As techytushar is suggesting, you were probably trying to call the function instead, right? In that case, you need to pass the arguments to it.

Vector Sigma
  • 194
  • 1
  • 4
  • 16