Python

Python

List Comprehension has 7 Questions
What is the output of the following?
k = [print(i) for i in my_string if i not in "aeiou"]

prints all the vowels in my_string
prints all the consonants in my_string
prints all characters of my_string that aren't vowels
prints only on executing print(k)
What is the output of print(k) in the following?
k = [print(i) for i in my_string if i not in "aeiou"]
print(k)

all characters of my_string that aren't vowels
a list of Nones
list of Trues
list of Falses
What is the output of the following?
my_string = "hello world"
k = [(i.upper(), len(i)) for i in my_string]
print(k)

[('HELLO', 5), ('WORLD', 5)]
[('H', 1), ('E', 1), ('L', 1), ('L', 1), ('O', 1), (' ', 1), ('W', 1), ('O', 1), ('R', 1), ('L', 1), ('D', 1)]
[('HELLO WORLD', 11)]
none of the mentioned
What is the output of the following?
x = [i**+1 for i in range(3)]; print(x);

[0, 1, 2]
[1, 2, 5]
error, **+ is not a valid operator
error, ';' is not allowed
What is the output of the following?
print([i.lower() for i in "HELLO"])

['h', 'e', 'l', 'l', 'o']
'hello'
['hello']
hello
What is the output of the following?
print([[i+j for i in "abc"] for j in "def"])

['da', 'ea', 'fa', 'db', 'eb', 'fb', 'dc', 'ec', 'fc']
[['ad', 'bd', 'cd'], ['ae', 'be', 'ce'], ['af', 'bf', 'cf']]
[['da', 'db', 'dc'], ['ea', 'eb', 'ec'], ['fa', 'fb', 'fc']]
['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf']
What is the output of the following?
print([if i%2==0: i; else: i+1; for i in range(4)])

[0, 2, 2, 4]
[1, 1, 3, 3]
error
none of the mentioned