python loops
#x starts at 1 and goes up to 80 @ intervals of 2
for x in range(1, 80, 2):
print(x)
python loops
#x starts at 1 and goes up to 80 @ intervals of 2
for x in range(1, 80, 2):
print(x)
for loop python
Python Loops
for x in range(1, 80, 2):
print(x)
words=['zero','one','two']
for operator, word in enumerate(words):
print(word, operator)
for x in range(1, 80, 2):
print(x)
for loops python
text = "Hello World"
for i in text:
print(i)
#Output
#H, e, l, l, o, , W, o, r, l, d
for i in range(10):
print(i)
#1, 2, 3, 4, 5, 6, 7, 8, 9, 10
how to use for loops python
#simple for loop to print numbers 1-99 inclusive
for i in range(1,100):
print(i)
#simple for loop to loop through a list
fruits = ["apple","peach","banana"]
for fruit in fruits:
print(fruit)
python for loop
# A for loop in python is used to iterate (or loop) over a sequence.
# The sequence is usually range(start,end), but can also be a list.
# Example of for loop with range():
for num in range(1,10):
print(num)
# This prints all the numbers from 1 to 10, including 1 but excluding 10.
# Here is an example of a for loop with a list:
lst = [1,2,3,4,5]
for item in lst:
print(item)
# This prints all items in the list.
# For loops are also used in list comprehensions.
lst = [1,2,3,4,5]
new_lst = [item for item in lst if i % 2 == 0]
# The list comprehension above generates a new list, which new_lst is put equal to.
# It iterates through the items in lst and only puts them in the new list if it is a multiple of 2.
python for loop
for item in ['mosh','john','sarah']:
print(item)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us