Hi every one
I am facing a problem in deleting items from a list <<< Could any help me !!!

b=['a', 'b', 'r', 'g']
for c in b:
b.remove(c)

but when I check b
the result is

how can I delet all items using for loop

thanks

You can do like this:

>>> b=['a','b','r','g']
>>> for c in range(len(b)):
	del b[0]

	
>>> print b

You can refer to python docs for range function.

Thanks for ur reply

Maybe you can just set

b=[]

if you want to empty the list.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.