Python Forum
Have two class instances affect one another
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Have two class instances affect one another
#1
Hey everybody,

newbe here. I'm trying out classes and I don't know how to get the desired results:

class name():
    def __init__(self,name):
        self.name = name
        self.m = 0
    def one(self):
        if self.name == 'Jack':
            self.m = self.m + 5
            print(self.m)
    
    def two(self):
        if self.m > 0:
            print(self.m)
        else:
            print("no")
S = name('Jack')
P = name('Tom')
I want to start with S.one() and then use P.two() to get 5 but I always get 'no' instead.
Any feedback is welcome and appriciated Big Grin
Reply


Messages In This Thread
Have two class instances affect one another - by The_Zookinator - Jun-26-2019, 05:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [solved] Classes, assign an attributes to a class not to instances.. SpongeB0B 4 891 May-20-2023, 04:08 PM
Last Post: SpongeB0B
  How to create a varying qty of instances of a Class and name them? KM007 2 2,007 May-29-2020, 12:30 PM
Last Post: KM007
  Class Instances called in the wrong order IanIous 4 2,777 Mar-06-2020, 02:16 PM
Last Post: IanIous
  How to access class variable? instances vs class drSlump 5 3,285 Dec-11-2019, 06:26 PM
Last Post: Gribouillis
  Class Instances overriding class members and attributes. Leaf 7 6,860 Nov-29-2017, 06:08 AM
Last Post: Leaf
  Create class instances from list of strings pythonck 1 3,576 Sep-18-2017, 06:13 PM
Last Post: ichabod801
  List-Elements as instances of a class BigMan 3 4,255 Mar-25-2017, 06:55 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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