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 6698075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:32:05+00:00 2026-05-26T06:32:05+00:00

When and how are the builtin attributes initialized? __doc__ , __name__ (I guess I

  • 0

When and how are the builtin attributes initialized?
__doc__, __name__ (I guess I know about this one 🙂 ), __class__, __setattr__ etc.

In my other question regarding docstrings, one of the answers mentioned that docstrings are just simple strings and I tried with ', " and """ and they all worked. But when I used a variable assigned the string value and put that variable in place of the docstring, it doesn’t work. That’s why I started wondering when does the __doc__ attribute get initialized?

EDIT:
This is what I have tried on interpreter (yes, this is crazy and I am wierd :D)

doc_str = "Says Hello world"


class HelloWorld():
    def say():
        doc_str
        print("Hello world !")

h_w = HelloWorld()
h_w.say.__doc__


class AnotherHelloWorld():

    def __init__(self, doc_str="Says HELLO WORLD"):
        self.doc_str = doc_str

    def say(self):
        self.doc_str
        print("HELLO WORLD !")

a_h_w = AnotherHelloWorld("Scream... HELLO WORLD!")
a_h_w.say.__doc__


class YetAnotherHelloWorld():

    def __init__(self, doc_str="Still does't say HELLO WORLD :( "):
        self.doc_str = doc_str

    def say(self):
          "%s"%self.doc_str
          print("HELLO WORLD .. Again!")
  • 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-26T06:32:06+00:00Added an answer on May 26, 2026 at 6:32 am

    It’s different for each one. (After all, each one’s special!) Some are the class attributes, some are instance attributes, some are inherited.

    __doc__ is initialized when the class is created (you can also pass it in the dict argument to the type constructor). The special syntax only works for string literals, but if you need a variable docstring you can set it explicitly:

    class SomeClass(object):
        __doc__ = "This is class #{0}.".format(1)
    

    __name__ is also set when the class is created.

    __class__ is set when an instance is created (i.e. in __new__).

    __setattr__ and friends are inherited from object.

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

Sidebar

Related Questions

Does any Common Lisp (builtin) function return more than 2 values? I know many
Is there builtin method that would do this or do I always have to
Please help me with this WCF error....How do I handle these builtin classes for
Newbie question: unless I'm mistaken, most attributes appear to be benign until you use
The AssemblyVersion and AssemblyFileVersion attributes are the built-in way of handling version numbers for
There are no builtin matrix functions in C#, but there are in the F#
Is there a builtin function in PHP to intelligently join path strings? The function,
How can I extend a builtin class in python? I would like to add
I was looking at the builtin object methods in the Python documentation , and
i'm experimenting with django and the builtin admin interface. I basically want to have

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.