How ternary operators are used in python?



How ternary operators are used in python?..

Answer / Karan Vidyarthi

"In Python, the ternary operator (or conditional expression) is a shorthand for if-else statement. It has the syntax: result = (condition) * expression_if_true : expression_if_false. Here's an example: 'x' if x > 0 else 'n'."

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

What are the basic data types supported by python?

1 Answers  


What is the type of the given datatype a=1?

1 Answers  


Why is lambda used in python?

1 Answers  


What is the purpose of pythonpath environment variable?

1 Answers  


What are closures in python?

1 Answers  


How does the python version numbering scheme work?

1 Answers  


Explain split(), sub(), sub() methods of “re” module in python?

1 Answers  


How can you get the google cache age of any url or web page?

1 Answers  


Is python dict a hashmap?

1 Answers  


What’s your preferred text editor?

1 Answers  


Is self mandatory in python?

1 Answers  


Write a sample program in enumerate()function in python?

1 Answers  


Categories