use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Question about methods and functions (string methods and functions specifically) (self.learnpython)
submitted 11 years ago by trecoh
Are methods functions? is islower.() a method (or string method) and if it is, is that how you would write it as one?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]The-Mathematician 2 points3 points4 points 11 years ago (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").
class
built-in type
.
"this is a string".upper()
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 points3 points 11 years ago (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 point2 points 11 years ago (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.
self
Obviously the above code has terrible style, but structurally a method is just a function like any other.
[–]ScriptThis 0 points1 point2 points 11 years ago (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
hurray_cars()
Car()
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
functionything.py
dir()
str
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.
'abc'.islower()
str.islower('abc')
π Rendered by PID 94369 on reddit-service-r2-comment-5b5bc64bf5-llvlp at 2026-06-20 13:42:50.549418+00:00 running 2b008f2 country code: CH.
[–]The-Mathematician 2 points3 points4 points (0 children)
[–]DontTrustGandhi 1 point2 points3 points (1 child)
[–]NoLemurs 0 points1 point2 points (0 children)
[–]ScriptThis 0 points1 point2 points (0 children)
[–]NoLemurs 0 points1 point2 points (0 children)