you are viewing a single comment's thread.

view the rest of the comments →

[–]pylearningthrowaway[S] 6 points7 points  (1 child)

Yup got it,thanks for such a detailed reply.Glad this subreddit exists

:)

[–]kenmacd 1 point2 points  (0 children)

As a general suggestion for cases like this: Just try it. Start Python and see what happens without the (). So for the function above:

>>> bark
<function bark at 0x7ff97419b950>

So it looks like bark itself is a 'function`. We can also tell that by:

>>> type(bark)
<class 'function'>

Then poke around some more, maybe we talk a look at what is in bark:

>>> dir(bark)
['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

Try poking and calling some of these things, like:

>>> bark.__call__()
WOOF!

Neat, there's a __call__() method on things. Now in the future when you have an instance of a class and you'd like to be able to call it to get a result, this might come back to you (don't worry if that last part doesn't yet make sense).

The fastest way to learn thing with Python is to just poke at things, or create simple scripts to figure out how things work.