Python Forum
How to Call a method of class having no argument
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Call a method of class having no argument
#7
(Oct-31-2019, 12:03 PM)dataplumber Wrote: Is it necessary to have all the class methods should have at least 1 argument (self) in our case
all instance and class methods should have one argument. For instance methods, by convention, we call that argument self. For class methods we use, again by convention, cls.
And there are staticmethods that answer to your next question:
(Oct-31-2019, 12:03 PM)dataplumber Wrote: Can't we have no arguments ?

As ichabood explained
you need to declare it staticmethod. However in this case the question is does it really belong to a class or can simply be a function, outside class. i.e. if it doesn't need to access instance or the class

Google the difference between instance, class, static methods and simple function
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: How to Call a method of class having no argument - by buran - Oct-31-2019, 12:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  class definition and problem with a method HerrAyas 2 271 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  super() and order of running method in class inheritance akbarza 7 780 Feb-04-2024, 09:35 AM
Last Post: Gribouillis
  method call help sollarriiii 6 1,182 Feb-21-2023, 03:19 AM
Last Post: noisefloor
  Using one child class method in another child class garynewport 5 1,622 Jan-11-2023, 06:07 PM
Last Post: garynewport
  i want to use type= as a function/method keyword argument Skaperen 9 1,911 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  How to call a class in other class? 3lnyn0 3 944 Oct-24-2022, 09:18 AM
Last Post: GenTorossi
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 1,326 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  class, attribute and method Frankduc 9 2,490 Feb-27-2022, 09:07 PM
Last Post: deanhystad
  Subclass initialized property used in parent class method. Is it bad coding practice? saavedra29 5 1,805 Feb-07-2022, 07:29 PM
Last Post: saavedra29
  Class Method to Calculate Age Doesn't Work gdbengo 1 1,719 Oct-30-2021, 11:20 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020