Explain ternary operator in python?



Explain ternary operator in python?..

Answer / Deependra Kumar

The ternary operator in Python is a shorthand for an if-else statement. It consists of three parts: a condition followed by a question mark (`?`), then the expression to be executed if the condition is true, and finally the expression to be executed otherwise, separated by a colon (`:`). Here's an example:nn```pythonnx = 10ny = 'even' if x % 2 == 0 else 'odd'nprint(y)```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

What is tkiner?

1 Answers  


What are basic overloading methods in python?

1 Answers  


What is a raw input?

1 Answers  


What are the different environment variables identified by python?

1 Answers  


Differentiate between range and xrange.

3 Answers  


Explain how memcached should not be used in your python project?

1 Answers  


Give an example of shuffle() method?

1 Answers  


How is Python used in web development?

1 Answers  


How to test multiple variables against a value?

1 Answers  


What is arange function in python?

1 Answers  


What is the difference between range and xrange functions?

1 Answers  


What is super () in python?

1 Answers  


Categories