You are on page 1of 31

1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

CS 1101 Programming Fundamentals - AY2022-T2


Dashboard / My courses /
CS 1101 - AY2022-T2 / 16 December - 22 December /
Discussion Forum Unit 6 /
Discussion Unit 6

 Search forums

Discussion Forum Unit 6


Discussion Unit 6

Settings

Display replies in nested form

The cut-off date for posting to this forum is reached so you can no longer post to it.

Discussion Unit 6
by Leonidas Papoulakis (Instructor) - Wednesday, 10 November 2021, 7:11 AM

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. Do not copy them from the textbook or any other source.

92 words

Permalink

Re: Discussion Unit 6


by Samrawi Berhe - Friday, 17 December 2021, 3:07 PM

1. 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.

Answer

Description:-

An Object is a variable with a value in the list and we


say equivalent if different objects have the
same value item referenced

whereas a Value is a sequence of elements for the abject in a list. If objects are
the same and have the same value referenced
to that value, we call them identical
objects. Therefore, to check if the same object reference to the same value evaluates
to
True, we use an is operator (Downey A, 2015, p. 96).

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 1/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

Illustration:-

Object identity

From the above diagram, we


see that both a and b are referencing the same value and are identical. This
means the interpreter
knows a & b refer to the same memory location and hence
evaluates to True.
We use the
“is” operator to check the objects’
identicalness. So, let's test it.

Therefore, from the above


output, we see that a and b are identical and equivalent.

Object Equivalency

From the above diagram we


see that both a and b we call them variable or objects are also different memory locations are
referencing
to the same value. This means the interpreter knows a & b refer to a different memory location and hence
evaluates to False, when we check using an operator is, to check their identicalness. If they are identical,
then they must be
equivalent but they may not be necessarily identical (Downey
A, 2015, p. 96). So, let's test it.

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 2/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

So, we see from the above


output that a and b are not identical but they are equivalent since the equal
to “==” evaluates to
True.

2. Describe the relationship between objects, references, and aliasing. Again,


create your own examples with Python lists.

Answer

Description

As I
described in question #1 an Object in the list is a variable that is also a memory location. The Object
references a value in
memory location so that the interpreter uses it to do
some computation. This process is called object reference. When two
variable references a single value it
is called aliasing. It happens when a
variable "a" references to a value in a memory
location, i.e., a=[2,4,6,8,10], and b
is assigned to an i.e., b=a. then both variables are referencing a single memory
location
(Downey A, 2015, p. 96).

Illustration

Aliasing

   Therefore,
let’s test that using The "is" operator if it evaluates to True.

3.     
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.

Answer

My function accepts one argument and the argument is passed


upon the function call by reference. Generally, my function will
do four computations and uses list
traversing.  First, it will search an
upper case from the list and create a new list with the
upper case only. To do this I’m using a for loop and inside it, I am
using and if conditional to check for an
upper case in the list.

This can be done using the built-in isupper() function
and accessing it using a variable with a dot operator. Then if it meets
the condition, it will append using the built-in append()
 function, the traversed value, and create a new list with Upper case
only. Then the function returns the newly
created list. Second, it will copy the original list using the [:] indices slicing then print

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 3/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

out
it as it is. The third one is it will sort the list using the built-in function sort()
and is accessed using a variable name and
dot operator. Then prints out the
copied list which is passed as an argument to the function. The fourth
one is sorting using
the sorted() built-in function. This function is referenced by another variable called srtd_lst
and the original list is passed as an
argument to the built-in function sorted().
Then the value is printed out. Therefore, the script looks as follows.

def only_upper_case(t):

   res = []

   for s in t:

       if s.isupper():

           res.append(s)

   print('[output 5]', 'Copy of sorted Upper Case Only List from function call=', res)

   return res

xx = ['S', 'A', 'M', 'R', 'A', 'W', 'I', 'l', 'O', 'O', 'k', 's', 'H', 'a', 'P', 'p', 'Y']  # List is created here

print('[output 1]', 'Original List=', xx)  # This prints the original List

cp = xx[:]  # Keeping copy of the original list

print('[output 2]', 'Copy & unsorted List=', xx)  # Prints the copied list as it is.

cp.sort()  # Sort builtin functions is accessed here using var name with dot operator and sorts the copied list

srtd_lst = sorted(xx)  # A new variable srtd_lst is assigned (referenced) a sorted builtin functions

# and the sorted function is then passed the original list xx argument is passed to sort the list

print('[output 3]', 'Sorted List from sorted(function)=', srtd_lst)  # prints out the sorted original list

print('[output 4]', 'Copy of List & from sort(function)=', cp)  # prints out the sorted copied list

only_upper_case(cp)  # The function that prints the upper case is called and passed a parameter that contains

# the copied list

Then the output of


the above script is as below.

  Reference


 Downey,
A. (2015, p. 96 ). Think Python: How to Think Like a Computer Scientist
(2nd ed., Version 2.4.0). Needham: Green
Tea
Press.

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 4/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

906 words
Tags:
Discussion Forum Unit 6

Permalink Show parent

Re: Discussion Unit 6


by Luke Henderson - Tuesday, 21 December 2021, 3:24 AM

Great in depth and concise post from you as per usual. I like your use of stack diagram pictures to explain the concepts.
Great description of how an object is allocated into memory and great use of a handful of the built in python functions we
have used in recent assignments. Keep up the good work
56 words

Permalink Show parent

Re: Discussion Unit 6


by Samrawi Berhe - Tuesday, 21 December 2021, 9:35 AM

Thank you, Luke, for your comments.


6 words

Permalink Show parent

Re: Discussion Unit 6


by Fouad Tarabay - Tuesday, 21 December 2021, 1:27 PM

Hello Samrawi, the expanation was clear and informative. I liked that you used pictures and diagrams in your explanation
which make it more simple to read and understand.
28 words

Permalink Show parent

Re: Discussion Unit 6


by Ahmet Yilmazlar - Tuesday, 21 December 2021, 4:50 PM

Great explanation and it is quiite clear welldone


8 words

Permalink Show parent

Re: Discussion Unit 6


by Wilmer Portillo - Wednesday, 22 December 2021, 11:17 AM

Hi Samrawi,

Great Job on the details and illustration of your discussion. I always understand things I did not get on my own from your
work. You have a great career ahead in this field! Keep it up....
38 words

Permalink Show parent


Re: Discussion Unit 6


by Janelle Bianca Cadawas Marcos - Wednesday, 22 December 2021, 11:17 AM
https://my.uopeople.edu/mod/forum/discuss.php?d=640899 5/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

Nicely done, I can tell you spent a lot of time on this. It's a lot longer than mine and more in-depth. I like how you bolded
the important words. Great work.

32 words

Permalink Show parent

Re: Discussion Unit 6


by Juan Duran Solorzano - Wednesday, 22 December 2021, 3:09 PM

Great answer it helped me to fully understand the topic, this week was very confused for me but your answer helped me to
make the topic clear.

Nicely done!
29 words

Permalink Show parent

Re: Discussion Unit 6


by Crystal Noralez - Wednesday, 22 December 2021, 9:00 PM

This is an in-depth explain of the terms “equivalent” and “identical.” Keep of the great job.
16 words

Permalink Show parent

Re: Discussion Unit 6


by Stephen Chuks - Wednesday, 22 December 2021, 9:56 PM

Comprehensive and in depth. Keep it up

7 words

Permalink Show parent

Re: Discussion Unit 6


by Peter Odetola - Wednesday, 22 December 2021, 10:35 PM

Hello Samrawi, I really learn a lot from your unique perspective and the presentation.
14 words

Permalink Show parent

Re: Discussion Unit 6


by Ahmet Yilmazlar - Saturday, 18 December 2021, 2:16 PM

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.

Python programming language as we learnt earlierin unie one, is a formal language meaning that it has a well defined 
structure that must be adhered strictly to. And this structure like other programming langages uses objects to represent data.
Which is why it is saşd to be object oriented. (Downey A., 2015)

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 6/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

Now an objectfg is a collection of data (variables) and methods (functions defined within a class) that act on those data.
According to pythons docymentary. All data in a python program is represented by objrcts or by relations between objects.

Three things are characteristic of an object, namely:

. an identity

. a type

. a value

An objects identity is it address in memory. lt is uniqe and allocated at the point of instantiating object. The object type
determines the operations that an object supports and the possible values the object will accept and work with.

Now, the 'is' operator compares the identity of two objects; the id()function returns an integer representing its identity. While
the '=='operator checks for equivalence between two objects. Both operators returnvalue type is bool which means, they
either return a True or False value.

The following is a sample code to illustrate the difference between these operators;

Code:

==============================

a = [23, 34, 28]

b = [23, 34, 28]

c = a

def checks():

#id value changes each time the program is run.

print("ID of a is",id(a))

print("ID of b is",id(b))

print("ID of c is",id(c))

print()

#returns True | False because both are equivalent but different identities.

print(a == b,"|",a is b)

#returns both True | True because both are equivalent and have the same identity.
print(a == c,"|",a is c)

#returns True | False because both are equivalent but different identities

print(b == c, ''|",b is c)

checks()

Output:

==============================

ID of a is 489093885704

ID of b is 489086264456

ID of c is 489093885704

True | False

True | True


True | False

[Program finished]

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 7/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

The program above comprises of three lists and a function. The function is doing tree things;

First, it prints out the IDs of the three lists which are defined globally.

Secondly, it checks for equivalence between the given objects and outputs the result.

And thirdly it also checks the objects (in this case, lists) if they are identical using the 'is' operator.

As you can see, the ID of 'c' is same as that of 'a' which makes them identical and that is because we assigned 'a' to 'c' using
the assignment operator (=). On the contrary, 'b' is not identical thus the ID check returned False.

However, all three lists are equivalent because they all have the same value in their current state. But when the value of any of
the lists changes, they seize to be equal. This property of lists is called mutability (i. ability to change value).

Describe the relationship between objects , references , and aliasing. Again, create your own examples with Python lists.

"Like I mentioned earlier, when objects are created, they are created with atype and a value assigned to them. Another
important thing that happens isthat they are given a name or an identifier.

Now, the name of a variable for example, points to address in memory wherethe value of that variable is stored. For instance,
in the variable x = 5,'x' is the reference to address in memory where the value of the object(which is 5) is stored with type 'int'.

In a situation where the same memory location can be accessed using morethan one name is referred to as aliasing. For
instance, we have a variable,x = 5 if we then assign x to y;"

#we create a variable x with a value of 5

x=5

#assign variable x to y

y=x

This means that variables x and y are all pointing to the same object. And we can check this using the is operator

#comparing x and y will return True

x is y

#returns

True

The same thing applies to list a and c in our first example

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.

Code:

==============================


def modify(x, y):

a.append(45)

print(a)

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 8/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

print()

b.append(a)

print(b)

print()

b[2]=11

print(b)
print()
d=a+b

print(d)

print()

for i in a or c:
b.append(i)
print(b)

modify(a, b)

output:

==============================

[34, 23, 45]

[34, 23, [34, 23, 45]]

[34, 23, 11 ]

[34, 23, 45, 34, 23, 11]

[34,23,11,34]

[34,23,11,34,23]

[34,23,11,34,23,45]

[program finished]

The above program is a function defined with two parameters x and y. Thefunction is then called using lists a and b as
arguments.

The function is defined to test some operations that can be done on a list. As you see in the first statement, 'a.append(45)'
adds 45 to our list a.And 'b.append(a)' adds our list a to list b. List a becomes nested in list b. T he third operation, b[2]=11
changes the item with index 2, (which isour nested list a) to 11. The fourth d = a + b concatenates list a and b toform list d.
And in the fifth operation, the for loop does the same thingonly it adds the items of list b one at a time and prints the result
eachtime. Now earlier on we talked about references using variables as examples, inthe above function, the parameters
defined in the function and the names ofthose lists which we used as arguments to call the function are both alias because
they are both references to the same list objects and the are said to have been aliased

references

Downey, A. (2015). Think python, how to think like a computer scientist


985 words

Permalink Show parent

Re: Discussion Unit 6


by Samrawi Berhe - Monday, 20 December 2021, 4:28 AM

Hello Ahmet, Your overall work is great. You have explained what an Object is and the relationship between identity and
Equivalent greatly. The examples are also great but I noticed that you failed to explain the difference between object and

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 9/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

value. The other thing is you have typo errors and check your writing before you post.
56 words

Permalink Show parent

Re: Discussion Unit 6


by Luke Henderson - Tuesday, 21 December 2021, 3:20 AM

Well researched and descriptive post. You covered all the requested criteria in the post. However please take care to run
your work through an advanced spelling and grammar checker such as grammarly, as although the spelling for some of
the mistaken words are correct it has changed the meaning of the sentence for example when explaining your first
program you wrote "when the value of any of the lists changes, they seize to be equal." which should be cease to be equal.
82 words

Permalink Show parent

Re: Discussion Unit 6


by Fouad Tarabay - Tuesday, 21 December 2021, 1:33 PM

Hello Ahmet, everthing was great in your explanation you explained what is an object very well and the way of using the
identity function to expose the difference between the variable was very helpful to make it more clear.
39 words

Permalink Show parent

Re: Discussion Unit 6


by Simon Njoroge - Wednesday, 22 December 2021, 5:04 AM

Thanks for your input in this discussion. I appreciate the way you explained the concept clearly. Thanks . Keep up the good
work.
23 words

Permalink Show parent

Re: Discussion Unit 6


by Janelle Bianca Cadawas Marcos - Wednesday, 22 December 2021, 11:19 AM

Good work, you explained it all well. It would be good to proof read your work though, there are a lot of spelling errors
and stuff. Also to fix the spacing on the code, it's hard to read and didn't copy paste right. I have to always adjust the
spacing on mine after I copy paste from my word document. Keep it up.
63 words

Permalink Show parent

Re: Discussion Unit 6


by Wilmer Portillo - Wednesday, 22 December 2021, 11:21 AM

Hi Ahmet,

Excellent explanation even though you missed small portions of the discussion. I can see that you have a great
understanding of this weeks unit. Keep it up.

29 words

Permalink Show parent

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 10/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

Re: Discussion Unit 6


by Stephen Chuks - Wednesday, 22 December 2021, 10:05 PM

Good job. You did answered the questions and touched on the relevant points

13 words

Permalink Show parent

Re: Discussion Unit 6


by Simon Njoroge - Sunday, 19 December 2021, 1:56 PM

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.  

An object refers to unique data belonging to a specific class, for example string or integers. Values refers to specific
assignment to a valuable. For instance x = 6 where x is the object and 6 is the value assigned to the valuable. Equivalent is an
operator that shows identity or equal value referring to an object . Equivalence may be used as a Boolean relation to indicate if
an object is equal to another . The result is always True or False. While is also an operator it does not show equivalence of
value rather it shows if two objects are the same. For example x is y.

Example 1

https://my.uopeople.edu/pluginfile.php/1521284/mod_forum/post/15093950/script%20example%201.py

Describe the relationship between objects, references, and aliasing. Again, create your own examples with Python lists.

An object refers to shows identity of an equivalent value or


object. When showing they are one and the same thing this
relationship is shown
by aliasing. References is clearly showing an object showing relationship with
the other.  Look at the
following
example.

https://my.uopeople.edu/pluginfile.php/1521284/mod_forum/post/15093950/example%202%20discussion.py

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. 

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 11/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

Example for question 2 with explanations attached

https://my.uopeople.edu/pluginfile.php/1521284/mod_forum/post/15093950/question%202.py

237 words

Permalink Show parent

Re: Discussion Unit 6


by Samrawi Berhe - Monday, 20 December 2021, 4:36 AM

Hello Simon, your works are great. Your explanation and illustrations are very clear and informative. The way you present it
is also great. Keep it up!
26 words

Permalink Show parent

Re: Discussion Unit 6


by Luke Henderson - Tuesday, 21 December 2021, 3:12 AM

Great explanation of object, value, alias, reference and so on. Nice use of ide images to keep the program nicely formatted
and easily readable. I like how you showed that we can use == operator as well as "is"
39 words

Permalink Show parent

Re: Discussion Unit 6


by Fouad Tarabay - Tuesday, 21 December 2021, 1:36 PM

Hello Simon, your explanation was informative and clear, I liked how the code and the output was organized in the picture,
you did a great job!
26 words

Permalink Show parent

Re: Discussion Unit 6


https://my.uopeople.edu/mod/forum/discuss.php?d=640899 12/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

by Ahmet Yilmazlar - Tuesday, 21 December 2021, 4:51 PM

Your explanation and illustrations are very clear and informative great job
11 words

Permalink Show parent

Re: Discussion Unit 6


by Janelle Bianca Cadawas Marcos - Wednesday, 22 December 2021, 11:21 AM

I like the formatting you did with this, it's very clean and easy to read. It's also nice and short but gets all the info needed
out. Good work.
29 words

Permalink Show parent

Re: Discussion Unit 6


by Wilmer Portillo - Wednesday, 22 December 2021, 11:23 AM

Hi Simon,

As always your illustrations and comment are very helpful and instrumental in helping to gain more knowledge and
practice. Thank you very much for your contribution.
28 words

Permalink Show parent

Re: Discussion Unit 6


by Stephen Chuks - Wednesday, 22 December 2021, 10:10 PM

Concise and straight to the point. Keep it up

9 words

Permalink Show parent

Re: Discussion Unit 6


by Fouad Tarabay - Monday, 20 December 2021, 4:21 PM

The difference between objects and values is that objects store or holds values in them while values are of any type that can be
stored in an object.

The "is" operator is used to compare two objects which returns True if and only if the objects are identical

The objects are identical if and only if they contain the same values and are defined by the same variable name.

Example:

code:

x = ['hello',1,'world']

x = ['hello',1,'world']

print(x is x)

output: True

but suppose we have 2 objects which have the same values but a different variable name like:

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 13/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

code:

x = ['hello',1,'world']

y = ['hello',1,'world']

print(y is x)

output: False

In this case, these two objects are called "Equivalent" and in lists the “is” operator returns false if the objects are equivalent
(Downey, 2015).

------------------------------------------------------------------------------------------------------------------------------------------

The relationship between objects, references, and aliasing is that when we assign an object to a variable, this is called
referencing an object

Example:

x = [“Cars”,”Python”]

In the above statement here we are assigning x to the list [“Cars”,”Python”] and we say x refers to that list.

While aliasing is when we assign different variable to the same object

Example:

x = [“Cars”,”Python”]

y=x

here y will be equal to x

------------------------------------------------------------------------------------------------------------------------------------------

def Example(L):

L1 = [1,1,1]

L3 = []

for i in L:

for j in L1:

L3 += [i+j]
break

return L3

print(Example([4,5,6]))

Explanation of my example:

In the above code, we have a function that takes an argument L which is a list of 3 integers as a parameter. Inside the function,
we assign the list object of the values [1,1,1] to a variable named L1 by reference so L1 refers to that object similarly for L3 we
assign it to an empty list. In the two loops we worked with the values in L and L1 add each one and store it in L3, then after the
loop finishes the function returns the list L3.

Reference:

Downey A. (2015). Think Python: How to think like a computer scientist, 2nd Edition. (p.96).
342 words

Permalink Show parent

Re: Discussion Unit 6


by Yahya Al Hussain - Tuesday, 21 December 2021, 1:22 PM

great work, the description and code are clean and easy to understand, but the last example took some time because it
was missing the input.
25 words

Permalink Show parent


Re: Discussion Unit 6

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 14/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

by Ahmet Yilmazlar - Tuesday, 21 December 2021, 4:51 PM

great work
2 words

Permalink Show parent

Re: Discussion Unit 6


by Simon Njoroge - Wednesday, 22 December 2021, 5:05 AM

Your input in unit six discussion is well appreciated. I have learned a number of things in this discussion. Thanks for your
input.
23 words

Permalink Show parent

Re: Discussion Unit 6


by Peter Odetola - Wednesday, 22 December 2021, 10:44 PM

Dear Fouad, thanks for the concise and clear definition of the terms required as well as the detailed explanation of your
coding examples.
23 words

Permalink Show parent

Re: Discussion Unit 6


by Crystal Noralez - Monday, 20 December 2021, 8:41 PM

Discussion forum unit 6

Objects and Values using the terms “equivalent” and “identical”

1. 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.
Answer: Objects are data variables defined by class and can be compared to determine if they are "equivalent" or "identical". A
sting value would be and 'Hello, World!' and a floating number would be 42.0.

When two operations are equal or not, the term equivalent is used, and the value "true" and is returned if they are equal.

Example:

x = [19, 21, 24, 28] #partner, children and my birthdays

y = [11, 7, 3, 9 ] #partner, children and my birth months

z = x

def checks():

print("ID of x is",id(x))

print("ID of y is",id(y))

print("ID of z is",id(z))

print()

print(x == y,"|",x is y)

print(x == z,"|",y is z)

print(x == z,"|",y is x)

checks-()

Interpreter output

D:\Users\Crystal Noralez\Documents\sync\UoPeople\Term 3\Programming Fundamentals\Unit 6\Assessments\Discussion

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 15/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

forum unit 6.py

ID of x is 2316551449728

ID of y is 2316542558144

ID of z is 2316551449728

False | False

True | True

True | False

2. Describe the relationship between objects, references, and aliasing. Again, create your own

examples with Python lists.

Answer:

The reference is use to point to the location where the object's value of type 'int' is stored. Aliasing is a term used to describe a
situation in which the same memory region can be accessed using multiple names.

Example

x = 19, 21, 24, 28

y=x

x is y

return True

else: return False

The values of variable x are 19, 21, 24, and 28. As a result, we assign the same variable to y, implying that y refers to the same
value as x and that the values are not copied.

3. 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.

Example

x = [19, 21, 24, 28]

z = [x,1,2,3,4,5]

y = x+z

y[2]=-8

def checks():

print("ID of x is",id(x))

print("ID of y is",id(y))

print("ID of z is",id(z))

print()

print(x == y,"|",x is y)

checks()

Interpreter Output:

D:\Users\Crystal Noralez\Documents\sync\UoPeople\Term 3\Programming Fundamentals\Unit 6\Assessments\Discussion


forum unit 6.py

ID of x is 1957386971968

ID of y is 1957418620544

ID of z is 1957378015168

False | False

False | False

False | True


This function uses reference values due that “y=x+z”, meaning that “y” was using the same value as “x” and “z” to output its
value.

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 16/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

References

Downey, A. (2015). Think Python| How to Think Like a Computer Scientist: Vol. Version 2.2.23 (2nd Edition). Green Tea Press.
https://my.uopeople.edu/pluginfile.php/1404469/mod_page/content/3/TEXT%20-%20Think%20Python%202e.pdf
449 words

Permalink Show parent

Re: Discussion Unit 6


by Yahya Al Hussain - Tuesday, 21 December 2021, 1:27 PM

Crystal,

Great work and i must say that the first example was flawless, I enjoyed reading your answer.

keep it !
21 words

Permalink Show parent

Re: Discussion Unit 6


by Crystal Noralez - Wednesday, 22 December 2021, 9:01 PM

Thank you Yahya


3 words

Permalink Show parent

Re: Discussion Unit 6


by Wilmer Portillo - Monday, 20 December 2021, 8:55 PM

Discussion Assignment Unit 6:

1. 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.  
Objects are considered to be an instance of a Class, the procedure used to confirm whether two objects are identical is by the
use of the ‘is’ operator.

On the other hand, a value is considered to be an object on which a variable can be assigned to it, a method to state that two
values/operands are equivalent or not, is by the usage of the ‘==’ operator and the code returns ‘true’.
The ‘is’ operator is used to compare and tell whether two objects are identical or not.

Example #1:
Input:

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 17/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

Output:

Explanation:
In this case, the ‘is’ operator checked if the two variables that were assigned were directing to the same objects, as can be
observed list3 is directing to another object although is has the same data and considered ‘equivalent’ but it does no mean
that it is identical.

2. Describe the relationship between objects, references, and aliasing. Again, create your own examples with Python lists.

Objects have been described above.


Reference looks at the association between a variable and an object.

Aliasing refers to when there’s more than one reference for the same object that has an association to more than one variable.
In other words, if an element of the object is modified, both the variable that has the reference to the object will also be
modified.
Example#2:

Input:

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 18/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

Output:

Explanation: as can be seen in the comments in the input section, list1 and list2 refers to the same object, when the elements
was modified with index 2, the object was changed and hence the variables were modified, in other words aliasing occurred.
3. 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. 
Example:

Input:

Output:

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 19/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

Explanation: In the example above the function receives a list and elements(string) were added, the function got the reference
to the list.

References:

Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press. This book is licensed under Creative
Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0).

404 words

Permalink Show parent

Re: Discussion Unit 6


by Simon Njoroge - Wednesday, 22 December 2021, 5:06 AM

Your explanation and examples are well appreciated for this discussion. I have learned quite a lot from your input. Thanks
alot.
21 words

Permalink Show parent

Re: Discussion Unit 6


by Juan Duran Solorzano - Wednesday, 22 December 2021, 3:18 PM

Dear Wilmer,

Your answer is very well explained with concise examples, the definitions are simple and easy to understand.
19 words

Permalink Show parent

Re: Discussion Unit 6


by Crystal Noralez - Wednesday, 22 December 2021, 9:02 PM

I enjoy reading your explain. Well put together.


8 words

Permalink Show parent


Re: Discussion Unit 6
by Luke Henderson - Monday, 20 December 2021, 10:27 PM

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 20/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

Since Python is known as an object oriented language, therefore in Python everything is an object. So when we can create a
variable, for example:

x = 10

We created an object(x) which has the value of 10. As we have seen in previous units it is possible to have multiple variables
with the same name, sometimes they may only be available in the scope of a function depending on how we declare them.

Even if their name is the same and their value is the same, that does not mean they are the same object. They may have the
same value which makes them equivalent but they are not the same object which means they are not identical(Downey, 2015). 

We can check the truth behind these statements by using the Python functions “is” and “id()”. We use “is” to check if the values
are the same. When Python creates an object or reference it stores it in a specific address in memory. It is possible to use the
Python function id() to check that the specific address assigned to an object is the same as that of another object(Lenka, 2017).
Let's have a look at this in action.

Now here is a function I created to demonstrate the above concepts and its output placed side by side.

 
The function has the argument x which is just a placeholder for the list required. If any other input is given it will cause an error
since I use the append function which is exclusive to lists. When you call this function and pass a list to it as a parameter it will
assign that list to the object x and then append and sort the list. (Note it only works with a list of strings)

References

Lenka, C. (2017 November 25). id() function in Python. Geeks for Geeks. https://www.geeksforgeeks.org/id-function-python/

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 21/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

Downey, A. (2015). Think Python: How to think like a computer scientist. This book is licensed under Creative Commons
Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0)

333 words

Permalink Show parent

Re: Discussion Unit 6


by Samrawi Berhe - Tuesday, 21 December 2021, 9:59 AM

Hi, Luke, You have done great overall. You have explained in a clear and precise what an object and value together with
their relationship. Your illustration is also great. But it would be good if you were added some examples to show the
equivalence of those you explained.
48 words

Permalink Show parent

Re: Discussion Unit 6


by Yahya Al Hussain - Tuesday, 21 December 2021, 1:06 PM

Thank you for the post, i see you have used Geeks for Geeks, I'll have to check it out, the code is clean and easy to
understand, and the definition was helpful.
32 words

Permalink Show parent

Re: Discussion Unit 6


by Peter Odetola - Wednesday, 22 December 2021, 10:50 PM

Hi, Luke, You have done a good job but I would suggest a better white space in-between lines of code for a clearer
screenshot.
24 words

Permalink Show parent

Re: Discussion Unit 6


by Yahya Al Hussain - Tuesday, 21 December 2021, 10:55 AM

objects hold data such as values, a value is the basic building blocks of any function such as numbers int or characters string,
or a  boolean... etc. 

the value 2 and g=2 are equivalent, but b is identical to g if g=b,


here are some examples

Example1

>>>mylist1 = ["gold", "silver", "ore"]

>>>mylist2 = ["gold", "silver", "ore"]  #mylist1 is equivalent to mylist2

>>>mylist1 is mylist2                            #but they are not identical

>>>False

>>>mylist1 = mylist3                            

>>>mylist1 is mylist3                           #mylist1 is equivalent to mylist3

>>>true


A reference is the identifier used to access an object's value , aliasing is assigning that same value  identifier to another object
variable,

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 22/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

Example2

>>>my_list = [0, 1, 2]          #my_list is the object referencing the list [0, 1, 2]  
>>>id(my_list)

>>>4388520064

>>>his_list = my_list            #using  aliasing here both my_list and his_list are referencing the list [0, 1, 2]  

>>>id(his_list)

>>>4388520064

Example 3

#Function  takes 2 arguments, parameter a and parameter b adds them, then prints the  object a with the same reference ID

>>>def addto(a, b):

>>>    print('original reference IDs')

>>>    print(id(a))

>>>    print(id(b))   

>>>    a.append(b)

>>>    print(a)

>>>    print('New reference ID')

>>>    print(id(a))

>>>addto([0, 1, 2], 3)

>>>original reference IDs

>>>4452048768

>>>4384031024

>>>[0, 1, 2, 3]

>>>New reference ID

>>>4452048768

#Function  takes 2 arguments, parameter a and parameter b adds them, then prints the new object nw with a new reference
ID

>>>def addon(a, b):

>>>    print('old reference ID')

>>>    print('the reference id of a')

>>>    print(id(a))

>>>    print('the reference id of b')

>>>    print(id(b))

>>>    nw= a+b

>>>    print('new object nw is a + b')

>>>    print(nw)

>>>    print('new object nw has a new reference ID')

>>>    print(id(nw))

>>>addon([0, 1, 2], [5, 4])

>>>old reference ID

>>>the reference id of a

>>>4452043392

>>>the reference id of b

>>>4452056768

>>>new object nw is a + b

>>>[0, 1, 2, 5, 4]

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 23/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

>>>new object nw has a new reference ID

>>>4452124480

322 words
Tags:
Discussion Forum Unit 6

Permalink Show parent

Re: Discussion Unit 6


by Yahya Al Hussain - Tuesday, 21 December 2021, 1:20 PM

it seems i have forgotten to add something

instead of 

>>>mylist1 = mylist3
>>>mylist1 is mylist3  #mylist1 is equivalent to mylist3

>>>true

it should have been

>>>mylist1 = mylist3
>>>mylist1 is mylist3 #mylist1 is equivalent to mylist3

>>>true                       #mylist1 is identical to mylist3

43 words

Permalink Show parent

Re: Discussion Unit 6


by Crystal Noralez - Wednesday, 22 December 2021, 9:03 PM

You did a great job. well done in making you corrections. Your explanation  was very clear and understandable.
18 words

Permalink Show parent

Re: Discussion Unit 6


by Juan Duran Solorzano - Tuesday, 21 December 2021, 3:33 PM

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.

- Equivalent means that the two objects are the same object.
- Identical means that the two objects are the same object and have the same value.

The difference between objects and values is that objects are not the same object, but have the same value.:

- Objects are created when you assign a value to a variable.


- Values are the data that is stored in the variable.

Examples of equivalent and identical:



Identical:

name1 = "Juan" # name1 is an object

name2 = "Juan" # name2 is an object

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 24/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

This prints True because name1 and name2 are the same objects

print("name1 is name2:", name1 is name2)

Output:
name1 is name2: True

Equivalent:

name3 = ["Juan", "Carlos"] # name3 is an object

name4 = ["Juan", "Carlos"] # name4 is an object

This prints False because name3 and name4 are NOT the same objects

print("name3 is name4:", name3 is name4)

Output:
name3 is name4: False

The 'is' operator is used to check if two objects are the same object returning a boolean value.

Describe the relationship between objects, references, and aliasing. Again, create your own examples with Python lists.

Aliasing is when two variables point to the same object, but the variables are different.

This is an example of aliasing:

name5 = ["Juan", "Carlos", "Duran"] # name5 is an object

The following line creates a new object and name6 points to it. And a reference is created.

name6 = name5

The line below changes the value of name5 first item to "Solorzano" also changes the value of name6 creating an alias

name5[0] = "Solorzano"

print("name5:", name5)

Output:
name5: ['Solorzano', 'Carlos', 'Duran']

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.


list_to_modify = [1, 2, 3, 4, 5]

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 25/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6
print(list_to_modify) # Print the list without modifications

def modify_list(list_to_modify): # this function modifies the list passed as an argument

for i in range(len(list_to_modify)): # this will go through each element in the list

list_to_modify[i] = list_to_modify[i] * 5 # this will multiply each element by 5

newList = list_to_modify # this will create a new list with the same elements as the list passed as an
argument, using the same memory address

# newList gets the same value as list_to_modify because they are pointing to the same object in memory

return newList # this will return the new list with the new values

print("Modified list", modify_list(list_to_modify)) # this will print the modified list

Output:

[1, 2, 3, 4, 5]

Modified list [5, 10, 15, 20, 25]

References

Downey, Allen. (2015). Think Python: How to Think Like a Computer Scientist. Needham, MA: Green Tea Press

480 words

Permalink Show parent

Re: Discussion Unit 6


by Yahya Al Hussain - Tuesday, 21 December 2021, 3:59 PM

great post, the last example works perfectly, and the post is overall clean and easy to understand, but for the example
"name 5" and "name6" the last comment is untrue, for it to be true it has to go something like this

name5 = 0

name6 = name 5

name5 =1

print (name6)

>>> 0

name6 = name5

print (name6)

>>>>1

that's why in a function you should update both values once one has changed, or else a function wont work properly.
82 words

Permalink Show parent

Re: Discussion Unit 6


by Janelle Bianca Cadawas Marcos - Wednesday, 22 December 2021, 10:58 AM

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 26/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

Objects and values are different. Let’s say we have twins as


our ‘objects.’ They are equivalent to each other in appearance
and in family life. However, what is inside, their ‘values’ are
not identical. Twins are still their own person even if they are
equivalent at the start. They are still two different people. Two
different objects that have the same values, but that can change
in
the future. Values can change. Their values will deviate from each
other as they form separate experiences over time.

>>>James = ['blond hair','blue eyes','American'] #twin 1

>>>Jack = ['blond hair','blue eyes','American'] #twin 2

>>>James is Jack

       False

>>>Jack is James

       False

>>>#they are not the same person even if they are twins

The relationship between objects, references, and aliasing.


Taking our twins to help with explaining the relationship, the
twins
have their own nicknames used by their lovers. James is sometimes
called Jamie, while Jack is sometimes called Jackie.
These nicknames
are a different alias to refer to the twins (‘objects’). These
aliases are referencing to the object. Even if they’re
called by a
different name, they are still themselves. So if Jackie learned how
to play the piano, Jack knows how to play the
piano. If Jamie learns
guitar, then James can play guitar.

>>>Jamie = James

>>>Jamie is James

       True

>>>Jackie = Jack

>>>Jackie is Jack

       True

>>>Jamie += ['guitar'] #Jamie learned guitar

>>>James #James can play guitar

       ['blond hair', 'blue eyes', 'American', 'guitar']

>>>Jackie += ['piano'] #Jackie learned piano

>>>Jack #Jack can play piano

       ['blond hair', 'blue eyes', 'American', 'piano']

Sample function to modify list.


I created a function for if
the twins learn more things. The parameters are t and skill. The
argument for t would be one of the twins, the object. The t
references the object. The argument for skill would be a string for
the thing they learned.

>>>def learn_skill(t, skill): #add new skill to twins if


they want to learn more

            t += [skill]

            return t

>>>learn_skill(Jamie, ‘Spanish’) #James learns how to


speak Spanish

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 27/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

       ['blond hair', 'blue eyes', 'American', 'guitar',


'Spanish']

>>>learn_skill(Jackie, ‘French’) #Jack learns how to


speak French

       ['blond hair', 'blue eyes', 'American', 'piano', 'French']

>>>James

       ['blond hair', 'blue eyes', 'American', 'guitar',


'Spanish']

>>>Jack

       ['blond hair', 'blue eyes', 'American', 'piano', 'French']

References
Downey, A. (2015). Think Python: How to think like a computer
scientist. Green Tea Press. This book is licensed under Creative
Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0).

Re: Discussion Unit 6


by Juan Duran Solorzano - Wednesday, 22 December 2021, 3:29 PM

Dear Janelle,

I really like your examples as are very easy to follow, something I would like to add to your very detailed explanation, is the
+= operand what does it do? perhaps you could have added a comment saying this line will add an item at the end of the
list, and maybe you could have added another line to modify the list using square brackets to compare different ways of
modifying a list.

Overall very clear, and easy to follow.


82 words

Permalink Show parent

Re: Discussion Unit 6


by Stephen Chuks - Wednesday, 22 December 2021, 9:34 PM

Python variables and an object are almost an equivalent concepts. The identifier of a variables changes when giving the
variable a new value. That new values results in a new object being created.

The 'is' operator is used to check if two variables are equal or not

mylists=[10,20,30,50]

newlists=[30,50,40]

newlists=mylists

newlists is mylists

print(newlists)

Refereces have an aliance if they refer to the same object in memory during program execution.

A reference is a name that refers to the specific location in memory of a object 


86 words

Permalink Show parent

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 28/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

Re: Discussion Unit 6


by Peter Odetola - Wednesday, 22 December 2021, 10:08 PM

CS1101 DISCUSSION FORUM UNIT 6

Question 1

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.
Answer

Object is something a variable refer to that has a type and a value.

Equivalent is a statement that shows that objects have the same value.

Identical is use to show that two objects are equivalent. Note that if two objects are equivalent, they are not necessarily
identical. Variables that have the same objects are not identical but they are equivalent because they refer to different values,
and variables that have the same values means they are identical because they refer to the same values.

The ‘is’ operator compares the identity of two objects; the id() function returns an integer representing its identity. While the
‘==’ operator checks for equivalence between two objects. Both operators return value type is bool, which means, they either
return a True or False value.

>>> x = [11, 22, 33]

>>> y = [11, 22, 33]

>>> z = x == y

>>> print(x)

[11, 22, 33]

>>> print(y)

[11, 22, 33]

>>> print(z)

True

>>> c = x is y

>>> print(c)

False

>>>

Variables x and y points to the same list [11, 22, 33]. In variable z, x is equivalent to y. The return gives True. In the third line of
code, “x” and “y” have the same values. That means they are equivalent, and that is why when we use the “==”, we get a True
output. In a real sense, being a string, they refer to two different objects that have the same value and that is why when we use
the “is” operator, we receive a False output, which means they are not identical.

Question 2

Describe the relationship between objects, references, and aliasing. Again, create your own examples with Python lists.

Answer

Object is what a variable refers to.

Reference is the association between a variable and its value (object).

Aliasing is a circumstance where two or more variables refer to the same object. Variables store references to values.

>>> list1 = ['good', 'better', 'best']

>>> list2 = list1

>>> list1 is list2

True

>>> aliased = list1

>>> print(list1)

['good', 'better', 'best']

>>> aliased[2] = 'Excellent'


>>> print(list1)

['good', 'better', 'Excellent']

>>> aliased[1] = 'Superior'

>>> print(list2)

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 29/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6

['good', 'Superior', 'Excellent']

>>>

The output is “True” in forth line of code because list1 and list2 now refer to the same object. Therefore, list2 is an alias of list1

Question 3

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.

Answer

Create your own unique examples for this assignment. Do not copy them from the textbook or any other source.

>>> def add_value(c):

... c.append(44)

...

...
>>> b = [22,33]

>>>

>>> add_value(b)

>>>

>>> print(b)

[22, 33, 44]

>>> When c.append(44) is called, a list of object is passed into the function as an argument. Parameter ‘b’ contains the
references to the object. c.append(44) calls the method append to the object.

Downey, A. (2015). Think Python, How to think like a computer scientist. This book is licensed under Creative Commons
Attribution – Noncommercial 3.0 Unported (CC BY-NC 3.0)
557 words

Permalink Show parent

UoPeople Clock (GMT-5)

All activities close on Wednesdays at 11:55 PM, except for Learning Journals/Portfolios which close on Thursdays at 11:55 PM always
following the clock at the top of the page.

Due dates/times displayed in activities will vary with your chosen time zone, however you are still bound to the 11:55 PM GMT-5
deadline.

◄ Learning Guide Unit 6

Jump to...

Learning Journal Unit 6 ►

Disclaimer Regarding Use of Course Material  - Terms of Use


University of the People is a 501(c)(3) not for profit organization. Contributions are tax deductible to the extent permitted by law.
Copyright © University of the People 2021. All rights reserved. 

You are logged in as Stephen Chuks (Log out)


Reset user tour on this page
 www.uopeople.edu
https://my.uopeople.edu/mod/forum/discuss.php?d=640899 30/31
1/5/22, 1:49 AM CS 1101 - AY2022-T2: Discussion Unit 6










Resources
UoPeople Library
Orientation Videos
LRC
Syllabus Repository
Honors Lists
Links
About Us
Policies
University Catalog
Support
Student Portal
Faculty
Faculty Portal
CTEL Learning Community
Office 365
Tipalti
Contact us
English (‎en)‎
English (‎en)‎
‫ العربية‬‎(ar)‎

Data retention summary


Get the mobile app

https://my.uopeople.edu/mod/forum/discuss.php?d=640899 31/31

You might also like