Tell me how does the ternary operator work in python?



Tell me how does the ternary operator work in python?..

Answer / Shekhar Singh

The ternary operator (also known as the conditional expression) in Python is a shorthand way to write an `if-else` statement. It has the syntax `expression1 if condition else expression2`. Here's an example:n```pythonna = 5nb = 'even' if a % 2 == 0 else 'odd'nprint(b) # Output: even"`

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

How do you get the current working directory using python?

1 Answers  


How can we pass optional or keyword parameters from one function to another in Python?

1 Answers  


Why do we use raw_input in python?

1 Answers  


What is difference between input and raw_input in python?

1 Answers  


Why does the following behave unexpectedly in python?

1 Answers  


What is enumerate python?

1 Answers  


What is casting in python?

1 Answers  


What is list in python?

1 Answers  


How do I run notepad ++ in python?

1 Answers  


What is the key difference between java and python?

1 Answers  


What is python distutils?

1 Answers  


What are object methods?

1 Answers  


Categories