Python Forum
How to define a variable in Python that points to or is a reference to a list member
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to define a variable in Python that points to or is a reference to a list member
#1
I have a Python list, r[], and would like to define references, or aliases to specific members of the list. This is easy to do in languages with pointers (like C or C++), but I don't see how to do this in Python.

Specifically, I'd like do something like this:

r[0] = 1
ac (=addressof) r[0]
ac = 2

Now if I evaluate r[0] I need it to be 2

Is there a way to define such a reference in Python? I'm not looking for defining a class such that objects of that class can be references to each other. I'm looking for a simple means of pointing one variable to any other variable, but my current specific problem is a reference to a list member.
Reply


Messages In This Thread
How to define a variable in Python that points to or is a reference to a list member - by JeffDelmas - Feb-28-2021, 04:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Project Structure for Modularity and Reusability with Multiple Entry Points b19wh33l5 0 277 Apr-24-2024, 12:21 PM
Last Post: b19wh33l5
  Class member become static Quasar999 1 756 Sep-16-2023, 12:52 PM
Last Post: deanhystad
  Define Variable xinyulon 5 1,314 Nov-03-2022, 01:12 AM
Last Post: Larz60+
  Split string using variable found in a list japo85 2 1,385 Jul-11-2022, 08:52 AM
Last Post: japo85
  can Inner Class reference the Outer Class's static variable? raykuan 6 6,172 Jul-01-2022, 06:34 AM
Last Post: SharonDutton
  Points not plotting with reference to x-tick labels Mark17 2 1,352 Jun-14-2022, 05:38 PM
Last Post: Mark17
  labels.append(self.classes.index(member.find('name').text)) hobbyist 1 1,987 Dec-15-2021, 01:53 PM
Last Post: deanhystad
  An IF statement with a List variable dedesssse 3 8,614 Jul-08-2021, 05:58 PM
Last Post: perfringo
  How to use a variable in Python (2.x) to define decimal part? MDRI 4 2,411 May-07-2021, 12:39 AM
Last Post: MDRI
  Determine number of all the immediately adjacent points in python zackk 1 1,943 Feb-06-2021, 09:23 AM
Last Post: zackk

Forum Jump:

User Panel Messages

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