1

I am kind of new to python and there a certain time or certain method we use one approach on? Like when do we use functions with a . in front of them and when do we functions without a dot because it seems impossible to figure with method will be used when

i dont have examples

UpAndAdam
  • 4,515
  • 3
  • 28
  • 46
  • 2
    I don't think there's a way to know that except by memorization. You're aided by the fact that there are only 75 [builtins](https://docs.python.org/3/library/functions.html) (the ones like sorted().) Of those, probably only 10 of them are important. – Nick ODell Aug 18 '23 at 17:51
  • 3
    Typically, by reading the docs or experience. From your 2 examples given, `lower` makes sense as being a method of strings as it operates on strings specifically. `sorted`, on the other hand works on any iterable, so it makes sense as a function. – Axe319 Aug 18 '23 at 17:52
  • 4
    By consulting the documentation. Note `sorted` is not a method. It is just a function. It isn't impossible for `something(arg)` to be a method, but typically, methods are invoked directly off of their instances, e.g. `some_instance.some_method()` – juanpa.arrivillaga Aug 18 '23 at 17:57
  • 1
    Related: [What's the difference between a method and a function?](/q/155609/4518341) You might also want to read [What is the difference between `sorted(list)` vs `list.sort()`?](/q/22442378/4518341) (BTW [`random.shuffle`](//docs.python.org/3/library/random.html#random.shuffle) is an interesting counterexample.) – wjandrea Aug 18 '23 at 22:30

0 Answers0