Member-only story
Loops in Python {2}
4 min readDec 13, 2024
Hello,
Press enter or click to view image in full size![]()
31. Iterate Over Lines in a File
pythonCopy codewith open('example.txt', 'r') as file:
for line in file:
print(line.strip())32. Loop Over a Range with Floating Point Steps
pythonCopy codestart, end, step = 0, 1, 0.2
while start < end:
print(round(start, 2))
start += step33. Iterate Over a String in Reverse
pythonCopy codestring = "hello"
for char in reversed(string):
print(char)34. Skip Specific Elements in a for Loop
pythonCopy codenumbers = [1, 2, 3, 4, 5]
for num in numbers:
if num == 3:
continue
print(num) # Skips 335. Loop Through Two Lists Using zip
pythonCopy codelist1 = [1, 2, 3]
list2 = ["a", "b", "c"]
for x, y in zip(list1, list2):
print(x, y)






