Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use of Multiple Object
#1
I want to create two objects of a class. Using these two objects i want to input some numbers into a list which is a member of the class. After inputting data it will display the content of the list. Simple code. But the output was not which i want. I enclosed my python code and the output. Please tell me why the program is not working. I am new programmer in Python.
class Demo:
    arr = []
    n = 0

def __init__(self,s):
    self.n=s
def fill(self):
    print("Enter elements in array ")
    for i in range(self.n):
        x=input()
        self.arr.append(x)

def show(self):
    for i in range(self.n):
        print(self.arr[i])

obj1 = Demo(5)
obj2 = Demo(3)

obj1.fill()
obj2.fill()

print("Data from first Object")
obj1.show()
print("Data from second object")
obj2.show()
Output:
Enter elements in array  1 2 3 4 5 Enter elements in array  6 7 8 Data from first Object 1 2 3 4 5 Data from second object 1 2 3
Reply


Messages In This Thread
Use of Multiple Object - by arup - Mar-08-2017, 03:39 AM
RE: Use of Multiple Object - by Larz60+ - Mar-08-2017, 04:18 AM
RE: Use of Multiple Object - by arup - Mar-08-2017, 11:43 AM
RE: Use of Multiple Object - by buran - Mar-08-2017, 07:08 AM
RE: Use of Multiple Object - by merlem - Mar-08-2017, 10:04 AM
RE: Use of Multiple Object - by buran - Mar-08-2017, 04:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  connecting to the spreadsheet object inside multiple enterprise software apps ajetrumpet 0 1,654 Jan-19-2020, 03:36 PM
Last Post: ajetrumpet
  How to sharing object between multiple process from main process using Pipe Subrata 1 3,698 Sep-03-2019, 09:49 PM
Last Post: woooee
  Return Object Created from Multiple Classes emerger 3 3,113 Oct-18-2018, 02:14 AM
Last Post: emerger

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020