KnowledgeBoat Logo

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"]
  1. prints all the vowels in my_string
  2. prints all the consonants in my_string
  3. prints all characters of my_string that aren't vowels
  4. 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

3 Likes


Related Questions