Python Programming - Tricky Questions - Discussion
Discussion Forum : Tricky Questions - General Questions (Q.No. 9)
9.
What is the output of the following Python code?
my_list = [1, 2, 3, 4]
result = [x if x % 2 == 0 else -x for x in my_list]
print(result)
Answer: Option
Explanation:
List comprehension is used to create a new list where even numbers are unchanged, and odd numbers are negated.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers