Posts

Showing posts from August, 2017

Information passing in Python (Pass by object reference)

Image
Hello, reader! Are function calls "pass-by-value" or "pass-by-reference" in python?  If you have ever used functions in python, this doubt would have come to your mind. This post aims to simplify the commonly used answer, " Object references are passed by value.", and explain the concept from the basics. Pre-requisite knowledge:     1. Everything is an object in python. In Python, whenever an assignment statement, say, x = 2 is called, the 'identifier' (also called 'name') references an instance of int class having value 2. After that, if you call, y = x , an 'alias' is created which is also a name pointing to the same instance.      2. Python's built-in classes can be mutable or immutable. Consider two classes, float and list. You might know that float is an immutable built-in class defined in python, whereas, list is mutable. What it means is that if you do:         x = 2.0         y = x + 1.1 at firs