Range, Enumerate and Zip Functions
Range, Enumerate and Zip Functions
List function:
word = 'hello'
list(word) # Each character is added to a list
# To print each letter do:
for letter in list(word):
print(letter) # This will print each letter as a stand alone item as it loops throughRange function:
for num in range(10): # Up to but not including the 10
print(num) # Prints all the way up to 9
# Setting up a specific range:
for num in range(1,10): # Starts from 1 not from 0
print(num)
# Setting up the step size (or increment):
for num in range(2, 10, 2): # Starts from 2 goes to 3 all the way up to 8
print(num)ZIP function:
Enumerate function:
PreviousLooping and Unpacking with Dictionaries and TuplesNextMore Handy Functions and the Random Package
Last updated