Answers for "use of for in python"

3

python for loop

for i in range(3):
  print(i)
#prints:  0,1,2
Posted by: Guest on November-11-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

Python Answers by Framework

Browse Popular Code Answers by Language