- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 write inline if statement for print in Python?
Python provides two ways to write inline if statements. These are:
1. if condition: statement
2. s1 if condition else s2
Note that second type of if cannot be used without an else. Now you can use these inline in a print statement as well. For example,
a = True if a: print("Hello")
This will give the output:
Hello
a = False print("True" if a else "False")
This will give the output:
False
Advertisements