- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to provide multiple statements on a single line in Python?
More than one statements in a block of uniform indent form a compound statement. Normally each statement is written on separate physical line in editor. However, statements in a block can be written in one line if they are separated by semicolon. Following is code of three statements written in separate lines
a=10 b=20 c=a*b print (c)
These statements can very well be written in one line by putting semicolon in between.
a=10; b=20; c=1*b; print (c)
A new block of increased indent generally starts after : symbol as in case of if, else, while, for, try statements. However, using above syntax, statements in block can be written in one line by putting semicolon. Following is a straight forward example of a block of statements in a for loop
for i in range(5): print ("Hello") print ("i=",i)
This block can also be written in single line as follows −
for i in range(5): print ("Hello"); print ("i=",i)
However, this practice is not allowed if there is a nested block of statements.
- Related Articles
- How is it possible to enter multiple MySQL statements on a single line?
- How can we combine multiple print statements per line in Python?
- Multiple Statements in Python
- How to Transpose a matrix in Single line in Python?
- How to indent multiple if...else statements in Python?
- How to add multiple graphs to a Plotly Dash app on a single browser page in Python Plotly?
- How to execute Python multi-line statements in the one-line at command-line?
- Plotting a horizontal line on multiple subplots in Python using pyplot
- How to write a single line in text file using Python?
- Multiple Assignments to Single Value in Python
- How to provide new line in JavaScript alert box?
- Multi-Line Statements in Python
- How to concatenate multiple C++ strings on one line?
- How to save multiple plots into a single HTML file in Python Plotly?
- How do we write Multi-Line Statements in Python?
