Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python List clear()

# list of cars
cars = ['Benz',('volkswagen','BMW'),'Ford','Ferrari',('volkswagen','BMW')]
numbers= [1,(1,3),5,7,(1,3),3,1,6,(1,3)]

# deletes all the elements in the car list
del cars[:]
print("After clearing the car list = ",cars)

# deletes all the elements in the number list
del numbers[:]
print("After clearing the number list = ",numbers)
Comment

Python List clear()

# list of cars
cars = ['Benz',('volkswagen','BMW'),'Ford','Ferrari',('volkswagen','BMW')]
numbers= [1,(1,3),5,7,(1,3),3,1,6,(1,3)]

# clear the car list
cars.clear()
print("After clearing the car list = ",cars)

# clear the number list
numbers.clear()
print("After clearing the number list = ",numbers)
Comment

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
Comment

PREVIOUS NEXT
Code Example
Python :: python use cases 
Python :: python pandas merge dataframe 
Python :: Creating lambda expressions in comprehension list 
Python :: how to check a string in if statement python 
Python :: python size of list 
Python :: json diff python 
Python :: k-means clustering 
Python :: remove element from a list python 
Python :: python generators with for 
Python :: python csv to excel 
Python :: queryset django 
Python :: how to make a letter capital in python 
Python :: print column name and index 
Python :: enum 
Python :: flask echo server 
Python :: spotify recommendations 
Python :: convert string input into a nested tuple in python 
Python :: python str and repr 
Python :: how to write a first program in machine learning 
Python :: Multiple page UI within same window UI PyQt 
Python :: python macro ensurepip py3 
Python :: best api for python 
Python :: showing typle results with for loop in py 
Python :: indexers in python 
Python :: python download from digital ocean spaces boto3 
Python :: 144/360 
Python :: select randomly from list in loop 
Python :: python 2.0 
Python :: numpy how to apply interpolation all rows 
Python :: python get function from string name 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =