Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 747 Bytes

Iterables.md

File metadata and controls

36 lines (24 loc) · 747 Bytes

Iterables = An object/collection that can return its elements one at a time, allowing it to be iterated over in a loop

List, Tuple, Set my_list = [1, 2, 3, 4, 5] my_tuple = (1, 2, 3, 4, 5) my_set = {"apple", "orange", "banana", "coconut"} my_name = "Bro Code"

for item in my_list: print(item)

for item in my_tuple: print(item)

for item in my_set: print(item)

for item in my_name: print(item)

DICTIONARIES my_dictionary = {'A': 1, 'B': 2, 'C': 3}

for key in my_dictionary: print(key)

for value in my_dictionary.values(): print(value)

for key, value in my_dictionary.items(): print(f"{key} = {value}")

ref : [[For loops]], [[list()]], [[Tuple()]], [[Set{ }]], [[Dict{}]]