Can global variable be passed into Python function?

Chris Angelico rosuav at gmail.com
Sat Feb 22 08:29:02 CET 2014


On Sat, Feb 22, 2014 at 6:18 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Now I daresay that under the hood, Pascal is passing the address of foo
> (or bar) to the procedure plus, but inside plus you don't see that
> address as the value of b. You see the value of foo (or bar).
>
> C does not do that -- you have to manually manage the pointers yourself,
> while Pascal does it for you. And Python also has nothing like that.

Yep. I should have clarified that I wasn't talking about Pascal; I'm
not fluent in the language (last time I did anything at all with
Pascal was probably about ten years ago, and not much then). In C, it
strictly does what I said: & takes the address of something, *
dereferences an address. There's no way to "pass a variable" - you
have to pass the address, and that has consequences if, for instance,
you *return* an address and the variable ceases to exist. (Does Pascal
have an equivalent of that?)

And Python has no such concept, anywhere. But anything that you can
achieve in C using pointers, you can probably achieve in Python using
more complex objects.

ChrisA



More information about the Python-list mailing list