Which of these words are reserved words in Python

Which of these words are reserved words in Python

A) iterate
B) continue
C) else
D) break

The correct answer to this question “Which of the following of these words are reserved words in Python?” is option (B, C, D) CONTINUE, ELSE, BREAK

Explanation: In Python programming, reserved words define the structure of Python programs, so they cannot be replaced or redefined by the user. Python uses reserved words to control the flow of programs, such as if, else, while, for, def, and return.

Table of contents: 

Understanding Iterate, Continue, Else, and Break in Python

Option A: Iterate in Python

Iterate is not a reserved word in Python. Iteration refers to the process of looping over the elements in a collection like a list, tuple, dictionary, set, etc. to access each item one by one. 

Example : 

my_list = [1, 2, 3, 4]

for item in my_list:
    print(item)

Output: 

Using “for-loop” is the most common method in iteration over a collection of elements. 

Option B: Continue Keyword in Python

Continue is a reserved keyword in Python. It is used within loops like for loop or while loop to skip the current iteration and move directly to the next iteration of the loop.

 If you want to ignore certain values in a loop based on a condition, the continue keyword can be useful.

Example :

i = 0
while i < 5:
    i += 1
    if i == 3:
        # Skips the iteration when i is 3
        continue 
    print(i)

Output : 

The continue statement in Python skips the current iteration of the loop when the condition is met ( i == 3). 

Option C: Else Keyword in Python 

Else is another reserved keyword in Python that is used in conditional statements and loops. It defines a block of code that is executed when the associated if or elif condition is not true.       

Example: 

x = 15
if x > 20:
    print("x is greater than 20")
else:
    print("x is less than or equal to 20")

Output: 

Here, the condition (x > 20) is false, so the code in the else block will execute.

Option D: Break keyword in Python

Break is also a reserved keyword in Python. The break keyword is used to exit the loop before the due time. When the break is encountered, the loop is immediately terminated, and the program continues from the code following the loop (for and while).

Example :

for i in range(10):
    if i == 5:
        print("Breaking the loop at i =", i)
        # Exits the loop when i equals 5
        break 
    print(i)

Output: 

Here, when i == 5, the break statement is executed, and the loop stops immediately.

Conclusion

In Python, iterate is not a reserved keyword whereas continue, else, and break are reserved keywords that control loop behavior and conditional logic. These keywords help define the flow of execution in programs.

About the Author

Senior Consultant Analytics & Data Science

Sahil Mattoo, a Senior Software Engineer at Eli Lilly and Company, is an accomplished professional with 14 years of experience in languages such as Java, Python, and JavaScript. Sahil has a strong foundation in system architecture, database management, and API integration. 

Full Stack Developer Course Banner