Answers for "python for loo"

37

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)
Posted by: Guest on April-07-2020
3

python for loop

for i in range(5):
	print(i) #0, 1, 2, 3, 4
for i in range(2, 8):
  	print(i) #2, 3, 4, 5, 6, 7, 8
for i in range(2, 10, 2):
  	print(i) #2, 4, 6, 8, 10
for i in (['a', 'b', 'c']):
  print(i) #a, b, c
Posted by: Guest on December-29-2020
1

python for loop

# Python for loop

for i in range(1, 101):
  # i is automatically equals to 0 if has no mention before
  # range(1, 101) is making the loop 100 times (range(1, 151) will make it to loop 150 times)
  print(i) # prints the number of i (equals to the loop number)
  
for x in [1, 2, 3, 4, 5]:
  # it will loop the length of the list (in that case 5 times)
  print(x) # prints the item in the index of the list that the loop is currently on
Posted by: Guest on January-09-2021
11

for in python

# how to use for in python for (range, lists)
fruits = ["pineapple","apple", "banana", "cherry"]
for x in fruits:
  if x == "apple":
    continue
  if x == "banana":
    break
  print(x)
# fron 2 to 30 by 3 step
for x in range(2, 30, 3):
  print(x)
Posted by: Guest on March-26-2020
2

python for loop

# Range:
for x in range(5):
  print(x) # prints 0,1,2,3,4

# Lists:
letters = ['a', 'b', 'c']
for letter in letters:
  print(letter) # prints a, b, c
  
# Dictionaries:
letters = {'a': 1, 'b': 2, 'c': 3}
for letter, num in letters.items():
  print(letter, num) # prints a 1, b 2, c 3
Posted by: Guest on October-04-2020
0

python for loop

#for loop without passing a argument

for _ in range(3):
  print("Hello")
Posted by: Guest on November-02-2020

Python Answers by Framework

Browse Popular Code Answers by Language