What is for-else and while-else in python?
Answer / Rahul Tiwari
For-else and while-else statements are used to execute a block of code when the loop does not terminate naturally. The block will be executed only if the loop completes its iteration without being interrupted by a break statement:n```pythonnfor i in range(10):n if i == 5:n breaknelse:n print('Iteration completed')nn # Output: Iteration completednIteration completedn...nIteration completednwhile True:n number = input('Enter a number (type "q" to quit): ')n if number == 'q':n breakn print(number ** 2)nn # Output:nEnter a number (type "q" to quit): 5n25nEnter a number (type "q" to quit): q"```
| Is This Answer Correct ? | 0 Yes | 0 No |
Is monkey patching considered good programming practice?
Explain supported data types in python?
How to import modules in python?
Different file processing modes supported by python?
What is meant by r strip() in python?
Can I use python instead of javascript?
What is a lambda form?
Explain garbage collection with python?
How do I sort a list in python 3?
Explain about python operators?
Explain about raising error exceptions?
How can I wait until we receive data using python socket?