- 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 use if...else statement at the command line in Python?
There are multiple ways in which you can use if else construct in the command line in python. For example, bash supports multiline statements, which you can use like:
$ python -c ' > a = True > if a: > print("a is true") > '
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. For example,
$ python -c $'a = True\nif a: print("a is true");'
This will give the output:
a is true
- Related Articles
- What is the ‘if...else if...else’ statement in Java and how to use it?
- How to use else statement with Loops in Python?
- How to indent an if...else statement in Python?
- What is the ‘if else’ statement in Java and how to use it?
- How to use else conditional statement with for loop in python?
- How to use ‘else if ladder’ conditional statement is C language?
- How to execute Python multi-line statements in the one-line at command-line?
- How to do Python math at command line?
- IF ELSE statement in a MySQL Statement?
- Java if-else statement
- How to use nested if statement in Python?
- What is the syntax of Python if...elif...else statement?
- Java if-else-if ladder statement
- Java if-then-else statement
- What is basic syntax of Python if...else statement?

Advertisements