Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python Clear()

l = ["a", "b", "c", "d", "e"]

for x in range(0, len(l)):
    if(len(l) == 0):
        print("Testing!")
#add a break here is you want the for loop to end after printing "Testing"
    l.clear()
    print(len(l))
#after you clear the list, the list is empty and len(l) will now equal 0. But the original range will stay the same 
#hence the for loop will continue even though the list has changed in size
Source by itsmycode.com #
 
PREVIOUS NEXT
Tagged: #Python
ADD COMMENT
Topic
Name
6+4 =