python for loop range
for i in range(0, 3):
print(i)
python for loop
#to print number from 1 to 10
for i in range(1,11):
print(i)
#to print a list
l = [1,2,3,4]
for i in l:
print(i)
r = ["a","b","c","d","e"]
s = [1,2,3,4,5]
#print two list with the help of zip function
for p,q in zip(r,s):
print(p,q)
how to iterate through range in python
for i in range(start, end):
dosomething()
#The i is an iteration variable that you can replace by anytthing. You do not need to define it.
range python 3
# range(start, stop, step)
# start = index to begin at (INCLUSIVE)
# stop = generate numbers up to, but not including this number (EXCLUSIVE)
# step = (can be omitted) difference between each number in the sequence
arr = [19,5,3,22,13]
# range(stop)
for i in range(len(arr)):
print(arr[i]) # prints: 19, 5, 3, 22, 13
# range(start, stop)
for i in range(2, len(arr)):
print(arr[i]) # prints: 3, 22, 13
# range(start, stop, step)
for i in range(0, len(arr), 2):
print(arr[i]) # prints: 19, 3, 13
# reverse:
for i in range(len(arr)-1, -1, -1):
print(arr[i])
for range python
for variable in range (69): # Runs the code below 69 times, sets the var "variable" to the index
print(variable) # Prints the var "variable" (every time the number will be bigger)
print("Done") # This will not get sent 69 times.
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