There are some functions/methods which do the the same work as other ones do.
>>> 3**3 and
from math import pow
Do they have some advantages over anothers??
Please inform if you know about some more pairs which do the same work.
Aymane Boukrouh [EXAMS]
I did not ask for the diff. between 'function' and method.
I asked for the diff. between relatively same fun. and methodes which outputs almost same.
like the second example
they output same all the time.
There are multiple functions that do the same work, and the advantages vary depending in the project you want to make. However, for small codes, it shouldn't matter, because after all it's just different names for the same thing.
Note that variable.sort() and sorted(variable) are NOT the same thing. variable.sort() changes the variable itself, while sorted(variable) only return a sorted version of it, but doesn't affect the variable.
EDIT: I just noticed you were asking for functions/methods and not different functions with same output. Your second example is confusing :/
This question has been asked many times before, please use the searchbar before asking next time please.
Yes, but if knowing the fundamental difference between the two types will justify the use of each one of them.
Both of the examples you gave are not really related to your question, because in the first example the function and method are different, and in the second one there is no clear usage of method, so you might want to give better examples.
However if they output the same result, then the only difference would be speed, and as I mentioned earlier speed is not very important for small codes.
There is no global definition to which is faster, so google is your friend if you want to know which one fits better.
If I understand your question correctly : at times, functions may use less CPU time than methods, but only some times. If execution speed is an issue, you can setup timers and compare which will be faster in your case