Computer Science
What will be the output of the following Python code snippet ?
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)
Linear Lists
2 Likes
Answer
prints all characters of my_string that aren't vowels
Reason — The expression [print(i) for i in my_string if i not in "aeiou"]
is a list comprehension that iterates over each character i
in the string my_string
. It checks if the character i
is not a vowel (i.e., it's not in the string "aeiou"). If i
is not a vowel, it prints the character i
.
Answered By
2 Likes
Related Questions
What will be the output of the following Python code ?
lst1 = "hello" lst2 = list((x.upper(), len(x)) for x in lst1) print(lst2)
- [('H', 1), ('E', 1), ('L',1), ('L',1), ('O', 1)]
- [('HELLO', 5)]
- [('H',5), ('E', 5), ('L',5), ('L',5), ('O', 5)]
- Syntax error
What will be the output of the following Python code ?
lst = [3, 4, 6, 1, 2] lst[1:2] = [7,8] print(lst)
- [3, 7, 8, 6, 1, 2]
- Syntax error
- [3, [7, 8], 6, 1, 2]
- [3, 4, 6, 7, 8]
Which of the following is the correct expansion of list1 = [expr(i) for i in list0 if func(i)] ?
(a)
list_1 = [] for i in list_0: if func(i): list_1.append(i)
(b)
for i in list_0: if func(i): list_1.append(expr(i))
(c)
list_1 = [] for i in list_0: if func(i): list_1.append(expr(i))
(d) none of these
Fill in the blanks:
A _________ is a named group of data of different data types which can be processed as a single unit.