The meaning of synonyms

Remember when I introduced in an earlier lesson the concept of synonym in Python. (At the time, we were teaching Reeborg a French synonym: avance = move.) What I call a synonym is normally referred to as a variable. And the notion of variables, and how they change, can sometimes be confusing to beginners. Let me try to explain some aspects to you using a little story.

John, Pierre and Antonio are three good friends that share a house. John is originally from England, Pierre from France and Antonio from Spain.

One day, John was speaking in English to Pierre. During that conversation, John said the word "once", referring to an event that occurred a single time. Pierre translated this concept in his mind as "une_fois".

Later that day, John was speaking in Spanish to Antonio. He mentioned his favourite number: "once" (11). Here's what it looks like in the Python interpreter:

>>> once = 1
>>> une_fois = once

>>> print 'once = ', once, '     une_fois = ', une_fois
once =  1      une_fois =  1

>>> once = 11

>>> print 'once = ', once, '     une_fois = ', une_fois
once =  11      une_fois =  1

The various words in human languages are associated with concepts or objects that are independent of the words used to represent them. So, "une_fois" is associated with the number 1, through its association with the word "once". However, "once" is just a word, not an object. So, when "once" takes on a different value later, the concept represented by "une_fois" is unchanged.

Let us look at a different story. John makes a groceries shopping list, with two items: "bananas" and "pears". He then tapes it on the fridge door. Later that day, Pierre walks by and notices the list too (une liste d'épicerie) which he associates with the word epicerie. Still later that day, John adds "apples" to the list. He notices that Antonio had already bought pears and remembers that they also need oranges. He thus scratches the item "pears" and replace it by "oranges". Here's how it looks in Python:

>>> groceries = ["bananas", "pears"]
>>> epicerie = groceries
>>> print groceries
['bananas', 'pears']
>>> print epicerie
['bananas', 'pears']

>>> groceries.append("apples")
>>> print groceries
['bananas', 'pears', 'apples']

>>> groceries[1]="oranges"
>>> print groceries
['bananas', 'oranges', 'apples']

>>> print epicerie
['bananas', 'oranges', 'apples']

Both John and Pierre are referring to the same object in their own language. When that object changes, it changes for both of them in the same way.

If, however, Pierre had made his own copy of the list, he would have been unaware of the changes made by John on the other list.

>>> groceries = ["bananas", "pears"]
>>> epicerie = list(groceries)
>>> groceries.append("apples")
>>> groceries[1] = "oranges"
>>> print groceries
['bananas', 'oranges', 'apples']
>>> print epicerie
['bananas', 'pears']
home
../images/SourceForge.net Logo