Why I can remove strings in list but not classes? Is it possible to do if there are classes in list? What is correct way to do this?
class Temp():
def __init__(self, name, name2):
self.n = name
self.n2 = name2
cltemp1 = Temp("1", "2")
cltemp2 = Temp("3", "4")
x = ["1", "2"]
clx = [cltemp1, cltemp2]
def remove_string_from_class():
global x
for x[:] in x:
del x[0]
remove_string_from_class()
print x
def remove_class_from_list():
global clx
for clx[:] in clx:
del clx[0]
remove_class_from_list()
print clx
TypeError: can only assign an iterable
for clx[:] in clxandfor x[:] in x?for c in clx[:]:while clxalso works. I'm curious, where does thefor x[:] in xcome from? It does look like it works on the string list, but I haven't seen it before.