Answers for "python for function"

17

for in python

for i in range(1,10,2): #(initial,final but not included,gap)
  print(i); 
  #output: 1,3,5,7,9
  
for i in range (1,4): # (initial, final but not included)
  print(i);
  #output: 1,2,3 note: 4 not included

for i in range (5):
  print (i);
  #output: 0,1,2,3,4 note: 5 not included

python = ["ml","ai","dl"];  
for i in python:
  print(i);
  #output:  ml,ai,dl
  
for i in range(1,5):	#empty loop...if pass not used then it will return error
  pass;
Posted by: Guest on May-18-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
1

python for loop

for _ in range(10):
  print("hello")
# Print "hello" 10 times
Posted by: Guest on February-08-2021
0

how to make loops in python

for x in range(0, 3):
    print("We're on time %d" % (x))
Posted by: Guest on July-08-2020
1

python for loop

fruits = ["apple", "banana", "cherry"]
for x in fruits:
    print(x)
Posted by: Guest on June-17-2021
-1

python for loop

for  i in data: #where data is your list or tuple
  print(i) #printing the values in data iteratively!
Posted by: Guest on October-06-2020

Python Answers by Framework

Browse Popular Code Answers by Language