Hacker News new | past | comments | ask | show | jobs | submit login

Don't be too afraid of pointers - you're already using them if you're using Python when you work with mutable structures.

    >>> a = {'foo': 0}
    >>> b = a
    >>> b['foo'] = 1
    >>> a['foo']
    1
    >>> id(a)
    140428021358832
    >>> id(b)
    140428021358832
`a` and `b` are just pointers to the underlying structure. The only difference is that Python is taking care of the dereferencing for you, whereas in C you would have to explicitly dereference the pointer.

That's all there is to them. It's a reference to another location in memory, which, when dereferenced, refers to that other location. In pseudocode:

    >>> b = 1
    >>> a = &b
    >>> b = 2
    >>> a*
    2
    >>> a* = 3
    >>> b
    3



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: