Answers for "python iterate number"

9

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)
Posted by: Guest on December-04-2020
7

python for loop

nums = ['one', 'two', 'three']
for elem in nums:
  print(elem)
Posted by: Guest on April-25-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
1

for i in range(n-1,0,-1):

# Print first 5 numbers using range function
for i in range(5):
    print(i, end=', ')

# Output:
# 0, 1, 2, 3, 4,
Posted by: Guest on December-17-2020

Code answers related to "python iterate number"

Python Answers by Framework

Browse Popular Code Answers by Language