Answers for "how to loop a loop in python"

74

python loops

#x starts at 1 and goes up to 80 @ intervals of 2
for x in range(1, 80, 2):
  print(x)
Posted by: Guest on January-19-2020
4

python loop

# A loop is used to iterate over a sequence
# The format of a loop is
for variable in object:
  pass

# A common use of a for loop is using the range() function
for num in range(1, 10):
  print(num)
  
# It can also be used with a list
new_list = ["Number 1", "Number 2", "Number 3", "Number 4"]
for x in new_list:
  print(x)
Posted by: Guest on April-27-2021
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
1

python for loop

for x in range(10):
	print(x)
// output: 1,2,3,...,10
    
for x in range(10, 20, 2):
	print(x)
// output: 10, 12, 14, 16, 18, 20

list = [2, 3, "el"]
for x in list:
	print(x)
// output: 2, 3, "el"

for _ in range(10):
  print("a");
// Do the loop without using index
Posted by: Guest on November-10-2020
0

for loop in python

data = [34,56,78,23]
sum = 0
# for loop is to iterate and do same operation again an again
# "in" is identity operator which is used to check weather data is present or not
for i in data:
  sum +=i
  
print(sum)
Posted by: Guest on December-09-2020
1

how to make a loop in python

x = 0
while True: #execute forever
	x = x + 1
	print(x)
Posted by: Guest on November-09-2020

Code answers related to "how to loop a loop in python"

Python Answers by Framework

Browse Popular Code Answers by Language