variables/objects passed by reference/value

This is because in python (unlike php) all variables are passed by reference, so they are generally considered to be mutable, however because some variable types in python are more complex, then they are immutable

I have read Ray's variables vs references article many times but I can not relate to python
Please give a php and python example of how variables are passed by reference
And if immutable in python, is variable passed by value? Relate this to php please.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Have a look at Python basics -- illustrated (part 3).

Whenever a Python variable appears in the source, you can be sure that there is some hidden dictionary where the name of the variable (as a string) is used as the key to the dictionary, and that the reference value (basically the address) is used as the value in the dictionary.

Whenever you access a Python object, you do it indirectly, via a reference to the object. Whenever you assign a variable, you only store a copy of the reference to the target object.

Whenever you pass any object in Python (and it does not matter whether it is mutable or immutable), you pass the reference value (the address of the target object when simplified a bit).

Actually, Python objects do not move during their existence. They sit on the same memory address and the address is used as their identity number (simplified). Only the references are copied (passed) on various places. Whenever you get the reference, you are able to reach the target object. The target object counts references that point to it; hence, it does not destroy itself if any reference exists.

For PHP vs. Python and mutability... In many languages the string type is used as an array of characters and the characters can be modified. This way, the same string object can change its content during lifetime. In other languages (like Python or Java), once the string is constructed, it cannot change its content. It is a kind of artificial restriction. Accepting that, you can pass the object by reference value, and you know that all parties will see the same string. If the string were mutable, you would have to copy the string if you wanted to pass the exact content.

References and mutability terms are orthogonal (unrelated, not affecting each other). You simply cannot modify a string in Python. Whenever you think it looks like you are doing so, the operation actually creates a modified copy of the original.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgb192, , you may get experts to give you "Explanations" about programming things in python that may not relate to PHP at all.

If I may ask, what are you now trying to do in "python" programming (to lean it), that you have to ask this question, in other words, if you can be more specific in questions about learning python, then you may can get more helpfull answers.
rgb192Author Commented:
If I may ask, what are you now trying to do in "python" programming (to lean it)

python basics illustrated part 3

I found part 2 but permission is denied

and I can not find part 1

I will read part 3 but may not understand until I read part1 and part2 first.

I like the visual diagram of examples of references and variables.  Ray wrote an article in honor of me for php (but I can not find). And Ray's article sometimes would be blocked 'permission denied'.
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

OK, i read your comment, and I briefly looked at pages for a beginner to learn, , that seems too academic for many to use,  you may can do well, if you start at the "Source for Python" at, and look at their Beginners Guide at, and there is a Difference in using programming in python ver 2 and using python ver 3 .

you may look at their list for tutorial links -,  but I am in no position to recommend any tutorial to you for Python programming. You may do well to ask a question in the EE Python zone, and ask experts to recommend a Python tutorial to use

Again, I will say that trying to "relate" python programming to php programming may be more confusing than helpful.
@rgb192: The links were temporarily unreachable (titles were changed). The new or modified articles must be approved by the page editor/moderator. This is the reason why some articles may be unreachable until then. The Part 1 and 2 has still the status Editor review. It should work a bit later:


But the order of reading depends on your previous experience. Reading only part 3 may be fine. Parts 1 and 2 are not Python related -- just explaining what may be needed to understand part 3 for some. Just try and write feedback there.
The part 1 and 2 were republished (should be available now).
rgb192Author Commented:
thanks for pass by reference/value
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.