Python Forum
How I can create reference to member of the class instance?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How I can create reference to member of the class instance?
#4
Still not sure if I understand, but is it this
class Cycler(object):
    def __init__(self, data):
        self.data = data
        
    def increase(self, value):
        self.data += value
        
# create instance of class Cycler        
cycler = Cycler(2)

#access instance property data
print(cycler.data)

#change instance property data
cycler.increase(3)

#access instance property data again
print(cycler.data)
You access members (properties and methods) using self. self being used to reference the instance is just a convention.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: How I can create reference to member of the class instance? - by buran - Dec-04-2018, 10:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How does this code create a class? Pedroski55 6 690 Apr-21-2024, 06:15 AM
Last Post: Gribouillis
  Class member become static Quasar999 1 765 Sep-16-2023, 12:52 PM
Last Post: deanhystad
  can Inner Class reference the Outer Class's static variable? raykuan 6 6,195 Jul-01-2022, 06:34 AM
Last Post: SharonDutton
  Cannot convert the series to <class 'int'> when trying to create new dataframe column Mark17 3 8,775 Jan-20-2022, 05:15 PM
Last Post: deanhystad
  labels.append(self.classes.index(member.find('name').text)) hobbyist 1 2,009 Dec-15-2021, 01:53 PM
Last Post: deanhystad
  Access instance of a class Pavel_47 5 2,210 Nov-19-2021, 10:05 AM
Last Post: Gribouillis
Exclamation win32com: How to pass a reference object into a COM server class Alfalfa 3 5,052 Jul-26-2021, 06:25 PM
Last Post: Alfalfa
  Class Instance angus1964 4 2,555 Jun-22-2021, 08:50 AM
Last Post: angus1964
  Create Generator in the Class quest 1 2,203 Apr-15-2021, 03:30 PM
Last Post: jefsummers
  How to define a variable in Python that points to or is a reference to a list member JeffDelmas 4 2,770 Feb-28-2021, 10:38 PM
Last Post: JeffDelmas

Forum Jump:

User Panel Messages

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