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

  • Home
  • SEARCH
  • 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 7065263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:56:06+00:00 2026-05-28T04:56:06+00:00

I’m just learning python and I’m not sure exactly what’s supposed to go in

  • 0

I’m just learning python and I’m not sure exactly what’s supposed to go in __init__. Normally I just see people writing self.arg = arg for each arg.

I just want to be completely sure I’m coding well. Is it okay if I have something like this:

def __init__(self, arg1):
    self.arg1 = arg1
    self.var1 = 0
    self.var2 = 0
    self.var3 = 0
    self.var4 = 0
    self.var5 = None
    self.var6 = None
    self.initialize_vars()

The reason for doing this is that I need to call a couple functions to get those values initialized. I’m not sure why but it seemed kind of wrong and I haven’t seen any similar examples so I wanted to check if it’s okay or not. If not, what might I do instead?

Also, is it bad to introduce self.var7, for example, in another function after __init__?

  • 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-28T04:56:07+00:00Added an answer on May 28, 2026 at 4:56 am

    I’d say that I agree on that good style code assigns all instance variables in __init__ because of readability, that is, anyone who takes a look at the code (even yourself in a couple of months) shouldn’t need to read the whole class implementation to have an idea about the variables and instance object of that class could hold.

    Aside from that, I’d rename initialize_vars method to _initialize_vars just to make it clear that is an internal method not expected to be used by the users of the class.

    To complete the information above, please have a look at PEP8:

    • single_leading_underscore: weak “internal use” indicator.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
For some reason, after submitting a string like this Jack’s Spindle from a text
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.