I'm havingg a problem with my code, I dont know why my code doesn't work. It works well when I use a string value to the condition variable, but not when I try to change a list.
Here is a copy of an example that works:
Now when i change the condition value for a list it doesnt work:
Does anyone know why this happens?
Here is a copy of an example that works:
class Car(object):
condition = "new"
def __init__(self, color):
self.color = color
def drive(self):
self.condition = "used"
chevy = Car("Blue")
print (chevy.condition)
ford = Car("Red")
print (ford.condition)
chevy.drive()
print (chevy.condition)
print (ford.condition)Result:Output:new
new
used
newThe ford condition is new as it shouldbe considerning the ford.drive() wasn't executed.Now when i change the condition value for a list it doesnt work:
class Car(object):
condition = ["0","0"]
def __init__(self, color):
self.color = color
def drive(self):
self.condition[0] = "1"
chevy = Car("Blue")
print (chevy.condition)
ford = Car("Red")
print (ford.condition)
chevy.drive()
print (chevy.condition)
print (ford.condition)Output:['0', '0']
['0', '0']
['1', '0']
['1', '0']In this example the ford condition change despite the ford.drive()has not been executed. Does anyone know why this happens?
