- 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 execute Python multi-line statements in the one-line at command-line?
There are multiple ways in which you can use multiline statements in the command line in python. For example, bash supports multiline statements, which you can use like −
Example
$ python -c ' > a = True > if a: > print("a is true") > '
Output
This will give the output −
a is true
If you prefer to have the python statement in a single line, you can use the \n newline between the commands.
example
$ python -c $'a = True\nif a: print("a is true");'
Output
This will give the output −
a is true
- Related Articles
- Multi-Line Statements in Python
- How do we write Multi-Line Statements in Python?
- How can I see how long statements take to execute on the MySQL command line?
- How to do Python math at command line?
- How to style multi-line conditions in 'if' statements in Python?
- How to use if...else statement at the command line in Python?
- Multi-Line printing in Python
- Command Line Arguments in Python
- How to add command line arguments in Python?
- How to run Python functions from command line?
- How to call Python module from command line?
- Command Line Interface Programming in Python?
- How to run Python functions in Eclipse command line?
- How to create a long multi-line string in Python?
- Command Line Interpreters

Advertisements