Python Code Execution Results
What is the output of the following python code? a= [1, 2, 3, 4] b= [num * 2 for num in a if num % = = θ] print(b)
Answer: [4, 8]
Explanation
- The list comprehension iterates through
a
, checks ifnum
is even (num % 2 == 0
), and if true, multipliesnum
by 2. - For the list
a = [1, 2, 3, 4]
, the even numbers are2
and4
. Multiplying them by 2 gives4
and8
.
Output: [4, 8]
This question appeared in
Past Papers (1 times)
SPSC Past Papers (1 times)
This question appeared in
Subjects (1 times)
COMPUTER (1 times)
Related MCQs
- What will be the output of the following python code? a= {1, 2, 3} b= {4, 5} c= a + b print (c)
- What is the output of the following C code? int main () { int x = 5; printf("%dn", x++); return 0;
- In a certain code language, PLAN is written as MQZM. How is CODE written in the same code?
- The most widely used code which represents each character as a unique 8-bit code is called:
- As per Section 290 of the Pakistan Penal Code 1860, Whoever commits a public nuisance in any case not otherwise punishable by this Code, shall be punished with fine which may extend to _______ rupees.
- "Code" means the Code of Criminal Procedure of ?
- A system software that translates high-level language source code into machine-level object code is called _____?
- In a code language, if BEAT is coded as 5642 and SWEET is coded as 66912, how would you code TEASE?
- In a certain code, BELIEF is written as AFKJDG. How is SELDOM written in that code language?
- In a code language MOBILE is written as ASDFGH, STORK is written as PLSQW. How is MOTORBIKE written in that code?