Comprehensions & Generators · Question 1 · Easy

A list comprehension applies a string method to every company name. What does it print?

print([w.upper() for w in ["tcs", "wipro"]])
  1. ['TCS', 'WIPRO']
  2. ['tcs', 'wipro']
  3. TCS WIPRO
  4. ['Tcs', 'Wipro']
Answer and explanation

Answer: A. ['TCS', 'WIPRO']

Explanation: The comprehension calls upper() on each string and collects the results in a new list, so both names come out fully in capitals.

Next: A comprehension with an if clause keeps only the passing marks (60 or more)…

Practise comprehensions & generators

Try a fresh set of comprehensions & generators questions with an explanation after every answer, free and without signing up: Comprehensions & Generators practice. Or sit a full placement mock test.

More comprehensions & generators questions

More python practice

Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge