Thursday, March 31, 2011

Mar 31

Starting todays with lists are mutable:
list are mutable program and example
This is a very easy concept to understand because really I this sorta when I was working with List Operators from my previous post. Basically how the list are mutable when you had to add 2 and 4 from my example in the above program, you basically did the same thing I did for list operators just all in this is that you inputed the numbers between multiple numbers instead of just putting them at the end or at the beginning.
List deletion:
list deletion program
Well really this method is pretty easy to understand due to all you have to do is put in a input to delete something within the list. Which from the program, del is asking you to do is delete the variable that is one in the list. Which happens to be two.
Objects and Values:
Objects and values program
When the objects and values you are listing aren't in a list then like from the program above you'd true for both a == b and a is b because they are equal. On the other hand you get false for a is b and you get true a == b because a == b is that a and b equal but for a is b, they aren't the same. They are two distinct lists of their own.
Aliasing:
aliasing program 
This program  basically says that variable a equals [1, 2, 3] and then variable b equals variable a so there for they are the same. When you input b[0] = 5, its changing what variable a = into [5, 2, 3]. This is because like I said, variable a and b are the same.
Cloning:
Cloning program
Frankly people believe cloning is pretty hard even though I believe this is pretty easy. Really the clone of this program is both b and d. This is due to the fact that they follow everything that a and c tell them to do because they equal what a and c [:] equals. So you can put as much as you want for b or d to change a and c, but they will always come out with their original values but will only change when assigned to a new value. 

1 comment:

  1. It is not that understanding the concept of aliasing and the need to copy a mutable object is difficult, but rather that failure to make copies can lead to subtle and difficult to find bugs in a program.

    ReplyDelete