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

The Archive Base Latest Questions

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

class x: def __init__(self): self.y=None self.sillyFunc(self.y) def sillyFunc(self,argument): if argument is None: argument=’my_name_as_argument’ self.printy()

  • 0
class x:
    def __init__(self):
        self.y=None
        self.sillyFunc(self.y)
    def sillyFunc(self,argument):
        if argument is None:
            argument='my_name_as_argument'
        self.printy()
    def printy(self):
        print self.y

According to me the above code should print >my_name_as_argument,where am i going wrong?

  • 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-15T08:20:20+00:00Added an answer on May 15, 2026 at 8:20 am

    In Python everything is an object and variables contain references to objects. When you make a function call it makes copies of the references. Some people including Guido van Rossum call this “Call by object reference”. Important note from Wikipedia:

    a function cannot change the value a variable references in its calling function.

    The code as you posted it prints nothing at all. I think you mean to add this extra line to your program:

    x()
    

    This then results in the output: None. This is not surprising because you are printing the value of self.y but the only value you ever assign to self.y is None.

    In Python, strings are immutable. Reassigning the value of argument only overwrites the local copy of the reference. It does not modify the original string.

    As you asked in a comment, if you use a mutable object and you reassign the reference, again this doesn’t do what you want – the original object is not affected. If you want to mutate a mutable object you can call a method that mutates it. Simply reassigning a reference does not change the original object.

    If you want self.y to point to a new object then you have to assign the object reference directly to self.y.

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

Sidebar

Related Questions

The following code works (and it's very simple): class Scrape(QApplication): def __init__(self): super(Scrape, self).__init__(None)
I have written this code: class component(object): def __init__(self, name = None, height =
class Pen(object): def __init__(self, mean_radius = None, length = None): self.usage = Is used
So I have a class like this: class Encoder(object): movie = None def __init__(self,
class Packagings: def __init__(self): self.length=0 self.deckle=0 self.tmp=0 self.flute=[] self.gsm=[] self.t_weight=0 self.weight=0 def read_values(self): print
code: class Node: def __init__(self, key, children=[]): self.key = key self.children = children def
It's my script: class shape: def __init__(self, name): self.name = name def printMyself(self): print
Suppose I have the following object: class Foo(object): def __init__(self, name=None): self.name = name
With the following tables and mappings class A: def __init__(self): self.id = None self.b_ids
I have the following Bird definition: class Bird: def __init__(self, swarm, position = None):

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.