Explain the use of ternary operator in python?



Explain the use of ternary operator in python?..

Answer / Sumit Rawat

The ternary operator, also known as conditional expression, is a shorthand for if-else statement in Python. It consists of three parts: an expression (test), a value to be returned when the test is true (then), and another value to be returned when the test is false (else). The syntax is as follows: `value_if_true if condition else value_if_false`

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

What do you understand by membership operators in python?

1 Answers  


What is string slicing in python?

1 Answers  


How do you insert a line break in python?

1 Answers  


What are the 3 types of numbers in python?

1 Answers  


Mention at least 3-4 benefits of using python over the other scripting languages such as javascript.

1 Answers  


How to count the occurrences of a perticular element in the list?

1 Answers  


What are the 5 tuples?

1 Answers  


What is the directory in python?

1 Answers  


What is *args and **kwargs?

1 Answers  


Who created the Python programming language?

1 Answers  


Will python work multiple inheritance?

1 Answers  


How to get class name of an instance in Python?

1 Answers  


Categories