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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:51:41+00:00 2026-06-18T00:51:41+00:00

I write a program in Python. I Have class A. one of its variables,v,

  • 0

I write a program in Python. I Have class A. one of its variables,v, is an instance of another class, B:

class A:
 def __init__(self):
   self.v = B()

the class B in in the form of:

class B:
 def __init__(self):
  self.list = [1,2,3]
 def function(self):
  self.list[2] = 1

I create an instance x=A(), put it in a list g (g=[x]) and then change one of the variables in x.v by printing g[0].v.function(). However, when I ask the computer to print g[0].v.list, it prints [1,2,3] rather then [1,2,1]. What can be the reason?

Thank you.

  • 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-06-18T00:51:42+00:00Added an answer on June 18, 2026 at 12:51 am

    Works for me:

    class A:
     def __init__(self):
       self.v = B()
    
    class B:
     def __init__(self):
      self.list = [1,2,3]
     def function(self):
      self.list[2] = 1
    
    x = A()
    g = [x]
    print g[0].v.function()
    print g[0].v.list
    

    output:

    None
    [1, 2, 1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to write a program in python where the user is given a
i have been trying to write a program in python to read two text
I have been asked to write a program using python for an assignment. I
If I write program in python 2.7 and I want to run another script
I have the following Python program: import xml.etree.ElementTree as ET import sys class MyXmlParser(object):
I have a program,But that not contain class concept ( Python program follow some
I have a python program which takes input from stdin. Now, I've to write
I'm trying to write a program in Python and I'm told to run an
I am trying to write a python program that calculates a histogram, given a
I need to write some input data files for a python program, and I

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.