Describe the difference between objects and values using the terms “equivalent” and “identical”. Illustrate the difference using your own examples with Python lists and the “is” operator.
Describe the relationship between objects, references, and aliasing. Again, create your own examples with Python lists.
Finally, create your own example of a function that modifies a list passed in as an argument. Describe what your function does in terms of arguments, parameters, objects, and references.
Create your own unique examples for this assignment.
the variable is created in a python by means of the sign "=" where on the left part there will be a name of a variable and on right values of a variable. The variable and an object in a python are praktichesik equivalent concepts. But there are distinctions as a python there are two types of objects:
1) unchangeable such as numerical data, lines, trains. For example at a
equate variables values an object the having
some identifier is created:
>>> a=2
>>> id(a)
1407502272
When giving the same variable of new value the identifier changes, that is is created new an object:
>>> a=2
>>> id(a)
1407502272
>>> a=5
>>> id(a)
1407502320
>>>
2) Changeable objects such as lists, dictionaries and many. For example we will appropriate to the list "a" some value and then we will equate new variables "b" to "a", having output references to "a" and "b" we will see that they are identical:
>>> a= [1.7]
>>> b=a
>>> print (id(a), id(b))
59042120 59042120
That is els we will add an element to Speke of "b", the list "a" will change too.
But if we create the list "с" and in a quality of value we will appropriate it the list "b", then the references "a" and "c" will not be equivalent:
>>> a is b
True
>>> c =list(b)
>>> a is c
False
Function:
>>> def add_value(a):
... a.append(7)
>>> b = [1, 0]
>>> add_value(b)
>>> print(b)
[1, 0, 7]
Comments
Leave a comment