So let me tell you why print(test, a) is working first.
When you call print(func) without function call (or in other words, without doing print(func()), what you are actually doing is printing the functions object, which happens to return a str representation of the function that contains the location of the function in memory.
def func():
return "Hello World!"
print(func) # >> <function func at 0x100858950>
print(func()) # >> Hello World!
print(func, "a") # >> <function func at 0x100858950> a
Now in regard to why you are receiving your error TypeError: unhashable type: 'list', this is due to the nature of a set and of a list. Notice the following will reproduce your exact error:
foo = [1, 2, 3]
set = {4, 5}
print(foo in set)
Outputs:
Traceback (most recent call last):
File "test.py", line 8, in <module>
print(foo in set)
TypeError: unhashable type: 'list'
This error is due to how set() works in Python. Notice the documentation for set() (here) states:
Return a new set or frozenset object whose elements are taken from iterable. The elements of a set must be hashable. To represent sets of sets, the inner sets must be frozenset objects. If iterable is not specified, a new empty set is returned.
A "hashable" element, defined by Python's doc here states:
An object is hashable if it has a hash value which never changes during its lifetime (it needs a __hash__() method), and can be compared to other objects (it needs an __eq__() method). Hashable objects which compare equal must have the same hash value.
What is going on is that a Python's list object is not hashable due to its very nature -- no __hash__() functionality.
class Foo:
foo = 1
a = 1
b = Foo()
c = "Hello World!"
d = [1, 2, 3]
Outputs:
1
280623165
-5794655848578721369
Traceback (most recent call last):
File "test.py", line 14, in <module>
print(d.__hash__())
TypeError: 'NoneType' object is not callable
In other words, lists are not hashable types in Python, and therefore you cannot check if they exist within a set since set will utilize the __hash__() functionality of objects to check if they exist within the set.
test?bis a set of numbers, so it cannot containlstwhich is a list, not a number.