Putting a simple if-then-else statement on one line [duplicate]

This question already has answers here: Does Python have a ternary conditional operator? (32 answers) Closed 2 years ago. The community reviewed whether to reopen this question 5 months ago and left it closed: Original close reason(s) were not resolved I’m just getting into Python and I really like the terseness of the syntax. However, … Read more

What is a Question Mark “?” and Colon “:” Operator Used for?

This is the ternary conditional operator, which can be used anywhere, not just the print statement. It’s sometimes just called “the ternary operator”, but it’s not the only ternary operator, just the most common one. Here’s a good example from Wikipedia demonstrating how it works: A traditional if-else construct in C, Java and JavaScript is written: if … Read more