What is the purpose of the range function in a for loop?
To create a list of numbers
To define the start and end of the loop
To generate a sequence of numbers
To specify the step size of the loop
What is the purpose of the enumerate function in a for loop?
To create an enumerated list
To generate a sequence of numbers
To iterate over two lists simultaneously
To access both the index and the value of elements in an iterable
How can you iterate over a string in reverse order using a for loop?
for char in reversed(string):
for char in string[::-1]:
for char in string.reverse():
Reverse iteration is not possible on strings
What will the following code output?
numbers = [3, 7, 2, 8, 5]
for i, num in enumerate(numbers):
if i == num:
break
print(num, end=' ')
What is the purpose of the else clause in a for loop?
To execute an alternative block of code
To specify the step size of the loop
To execute code when the loop is terminated normally
What will the following code output?
for char in 'hello':
if char == 'l':
break
print(char, end=' ')
What will the following code output?
numbers = [1, 2, 3, 4, 5]
for i, num in enumerate(numbers):
if i % 2 == 0:
continue
print(num, end=' ')
What will the following code output?
numbers = [1, 2, 3, 4, 5]
for i in range(len(numbers) - 1, -1, -1):
print(numbers[i], end=' ')
How can you iterate over the indices and values of a list using a for loop?
for i, value in enumerate(list):
for index, value in list:
for index in list.index():
for value in list.values():
How can you iterate over a tuple using a for loop?
for in in range(len(tuple)):
for i, element in enumerate(tuple):
There are 24 questions to complete.
Take a part in the ongoing discussion
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4