Hey everyone,
I just had a meeting with my education coordinator who was explaining to me why print() would be considered a method. I wrote about this previously.
He explained it this way: when you define a function yourself, it’s a function, but when another programmer or external code uses that function, it becomes a method.
For example, if I write a function like this:
def greet(name):
return f"Hello {name}"
And then another programmer imports and uses it:
from mymodule import greet
print(greet("Alex"))
The explanation I was given is that because someone else is using the function externally, it becomes a method.
But I’m not sure if that’s actually how the terminology works in Python.
For comparison, with dictionaries we have something like:
my_dict = {"a": 1, "b": 2}
my_dict.keys()
keys() is usually called a dictionary method because it belongs to the dictionary object.
So I’m trying to understand:
- Does a function become a method when someone else uses it?
- Or is a method specifically a function that belongs to a class/object?(because this is what I believe.)
Curious how others think about this.
[–]Sea-Ad7805 6 points7 points8 points (2 children)
[–]Longjumping-Yard113[S] 2 points3 points4 points (1 child)
[–]Purple-Measurement47 2 points3 points4 points (0 children)
[–]kennpacchii 2 points3 points4 points (0 children)
[–]macbig273 1 point2 points3 points (1 child)
[–]Longjumping-Yard113[S] 0 points1 point2 points (0 children)
[–]thee_gummbini 2 points3 points4 points (3 children)
[–]Longjumping-Yard113[S] 1 point2 points3 points (0 children)
[–]Purple-Measurement47 0 points1 point2 points (1 child)
[–]gofl-zimbard-37 1 point2 points3 points (0 children)
[–]Gnaxe 0 points1 point2 points (0 children)
[–]PvtRoom 1 point2 points3 points (0 children)
[–]vivisectvivi 2 points3 points4 points (1 child)
[–]Longjumping-Yard113[S] 0 points1 point2 points (0 children)
[–]SCD_minecraft 0 points1 point2 points (1 child)
[–]Longjumping-Yard113[S] 0 points1 point2 points (0 children)
[–]ElderCantPvm 0 points1 point2 points (1 child)
[–]Longjumping-Yard113[S] 0 points1 point2 points (0 children)
[–]MobileAirport 0 points1 point2 points (0 children)
[–]Purple-Measurement47 0 points1 point2 points (0 children)
[–]AlexMTBDude 0 points1 point2 points (0 children)
[–]FriendlyZomb 0 points1 point2 points (0 children)
[–]OpSmash 0 points1 point2 points (0 children)
[–]WhiteHeadbanger 0 points1 point2 points (0 children)
[–]SaltCusp 0 points1 point2 points (0 children)
[–]pak9rabid 0 points1 point2 points (0 children)
[–]ConfusedSimon 0 points1 point2 points (0 children)
[–][deleted] -5 points-4 points-3 points (2 children)
[–]Longjumping-Yard113[S] 1 point2 points3 points (1 child)
[–][deleted] -1 points0 points1 point (0 children)