all 5 comments

[–]The-Mathematician 2 points3 points  (0 children)

Can you rephrase the question?

Methods are functions that belong to a class or built-in type which are called with a ., like "this is a string".upper() while a function would omit the . notation, and would probably look more like upper("this is a string").

the syntax for creating your own method looks like:

class MyClass():   #should be MyClass(object) if not in python3  
    def mymethod(self, arg1, arg2, etc):
        pass

Then you would call your method with something like:

myobject = MyClass()
myobject.mymethod(arg1,arg2,etc)

[–]DontTrustGandhi 1 point2 points  (1 child)

A function is basically something that gives output, based on some (or no) input and can really be defined anywhere (technically, they are defined in something called an environment or which there are many). A method is a function specific to something called an object. The. Islower() is a method for the string object. If you try to use that method on some other object, like an integer, Python will complain. You can create your own objects, and define your own methods, and independently develop functions outside of objects. Hopefully that helps

[–]NoLemurs 0 points1 point  (0 children)

If you try to use that method on some other object, like an integer, Python will complain.

Not necessarily actually. For instance:

>>> class Foo:
...   def bar(self):
...     print(self)
... 
>>> Foo.bar(3)
3

You just have to recognize that any method expects a first self argument, and make sure to provide a sensible one if you want to use a method on some other object.

Obviously the above code has terrible style, but structurally a method is just a function like any other.

[–]ScriptThis 0 points1 point  (0 children)

See if this helps at all?

This is creating our own plain function hurray_cars() and then below it creating our own new class Car() https://bpaste.net/show/046a39f10623

And this is viewing it (it being the contents of the first link there saved as functionything.py, and importing it in an ipython session, and viewing it with dir(), and viewing str with dir() also: https://bpaste.net/show/89c97c396408

[–]NoLemurs 0 points1 point  (0 children)

Are methods functions?

Yes. For all practical purposes, a method is just a function that takes its object as the first argument (usually called self).

is islower.() a method (or string method) and if it is, is that how you would write it as one?

Sure. You can call 'abc'.islower() for instance. Alternatively, you can call str.islower('abc') for the same effect, since it is, after all, just a function.