Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4005168
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:21:41+00:00 2026-05-20T08:21:41+00:00

Suppose I have this code: class Num: def __init__(self,num): self.n = num def getn(self):

  • 0

Suppose I have this code:

class Num:
    def __init__(self,num):
        self.n = num
    def getn(self):
        return self.n
    def getone():
        return 1
myObj = Num(3)

print(myObj.getn()) # result: 3

But if I try print(myObj.getone()), I get an error: 'getone()' takes no arguments (1 given).

So I replace:

def getone():
    return 1

with

def getone(self):
    return 1

Now print(myObj.getone()) shows 1, as expected. But – getone() doesn’t need any arguments in order to just return 1. Do I have to use a meaningless argument?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:21:42+00:00Added an answer on May 20, 2026 at 8:21 am

    In Python:

    • Instance methods: require the self argument.
    • Class methods: take the class as a first argument.
    • Static methods: do not require either the instance (self) or the class (cls) argument.

    __init__ is a special function and without overriding __new__ it will always be given the instance of the class as its first argument.

    An example using the builtin classmethod and staticmethod decorators:

    import sys
    
    class Num:
        max = sys.maxint
    
        def __init__(self,num):
            self.n = num
    
        def getn(self):
            return self.n
    
        @staticmethod
        def getone():
            return 1
    
        @classmethod
        def getmax(cls):
            return cls.max
    
    myObj = Num(3)
    # with the appropriate decorator these should work fine
    myObj.getone()
    myObj.getmax()
    myObj.getn()
    

    That said, I would try to use @classmethod/@staticmethod sparingly. If you find yourself creating objects that consist of nothing but staticmethods the more pythonic thing to do would be to create a new module of related functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this code: class Example(object): def the_example(self): itsProblem = "problem" theExample =
Suppose I have code like this: template<class T, T initial_t> class Bar { //
Suppose to have a code like this: <div class=notSelected> <label>Name <input type=text name=name id=name
Suppose I have this code class Base{ public: int getVal(); private: int a, b;
Suppose I have this code (pseudocode) class SomeClass { class Person { public static
Suppose I have this code: var myArray = new Object(); myArray["firstname"] = "Bob"; myArray["lastname"]
I've seen second one in another's code and I suppose this length comparison have
Suppose you had code like this: _READERS = None _WRITERS = None def Init(num_readers,
Suppose I have template< unsigned int num > class SomeFunctionality { static unsigned int
Under $(document).ready(function() , I have the following code: num = $(#mainContentCategoryLinksWrapper > div).size(); This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.