
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to use single statement suite with Loops in Python?
Similar to the if statement syntax, if your while clause consists only of a single statement, it may be placed on the same line as the while header. Here are the syntax and example of a one-line for loop:
for i in range(5): print(i)
This will give the output:
0 1 2 3 4
- Related Articles
- How to use else statement with Loops in Python?
- How to use nested loops in Python?
- How to print a string two times with single statement in Python?
- How to use multiple for and while loops together in Python?
- How to use multiple modules with Python import Statement?
- How to use else conditional statement with for loop in python?
- How to use continue statement in Python loop?
- How to use nested if statement in Python?
- How to use IF statement in MySQL using Python?
- How to execute a single test from a large testing suite using TestNG.xml?
- Why python for loops don't default to one iteration for single objects?
- How to use multiple conditions in one if statement in Python?
- What is the use of the WITH statement in Python?
- How to get sequence number in loops with JavaScript?
- How to make loops run faster using Python?

Advertisements