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)
- [2, 6]
- [2, 4, 6]
- [4, 8]
- None of these
Explanation
- The list comprehension iterates through
a, checks ifnumis even (num % 2 == 0), and if true, multipliesnumby 2. - For the list
a = [1, 2, 3, 4], the even numbers are2and4. Multiplying them by 2 gives4and8.
Output: [4, 8]
Related MCQs
سادہ زبان کو مشینی زبان میں تبدیل کرنے کے عمل کو کیا کہتے ہیں؟
- Compiler
- Modem
- Interpreter
- Translator
اس سوال کو وضاحت کے ساتھ پڑھیں
- Serial advanced technic attachment
- Serial advanced technology attachment
- Serial advised technology attachment
- None of these
اس سوال کو وضاحت کے ساتھ پڑھیں
- Syntax Error
- Logical error
- Both A and B
- None of these
اس سوال کو وضاحت کے ساتھ پڑھیں
مندرجہ ذیل میں سے کون سا نان وولیٹائل اسٹوریج ڈیوائس ہے جو بجلی بند ہونے کے بعد بھی ڈیٹا محفوظ رکھتا ہے؟
- ROM
- RAM
- CPU
- None of these
اس سوال کو وضاحت کے ساتھ پڑھیں
کمپیوٹر نیٹ ورکس میں فائر وال کا بنیادی کام کیا ہے؟
- To filter/prevent/block unauthorized access
- To block viruses
- To speed up network traffic
- None of these