Posts

Showing posts with the label in

for in python

Image
#for else for x in range(2):     print('x : ', x) else:     print( 'Final x = %d' % (x)) #Strings as an iterable string = "Hello World" for x in string:     print('Hello World', x) #Lists as an iterable collection_list=[] collection = ['hi', 5, 'd'] for x in collection:     #print('collection', x)     collection_list.append(x) print('collection_list : ', collection_list)   list_for_range =[] #list for range for x in range(len(collection)):    #print(collection[x])    list_for_range.append(collection[x]) print('list_for_range : ', list_for_range) #Loop over Lists of lists list_of_lists = [ [1, 2, 3], [4, 5, 6], [7, 8, 9]] for list in list_of_lists:     for x in list:         print('list_of_lists ', x)