Strings
Arrays
Slices/Ranges
Booleans
Comprehensions
100

Which methods are used to change the case of strings?

upper() and lower()
100

How do you create an empty list and an empty set in Python?

[] or list() for a list, and set() for a set.

100

How do you slice the first 3 elements of a list lst?

lst[:3]

100

What will False and True evaluate to?

False

100

What is list comprehension used for?

To create lists in a concise way

200

How would you access the last character of a string s?

s[-1]

200

What method is used to add an element to a list and to a set?

append() for a list, and add() for a set

200

What is the result of range(5)?

range(0, 5) (which is equivalent to [0, 1, 2, 3, 4]

200

What does False or (3 > 1) evaluate to?

True

200

What is the output of [x**2 for x in range(3)]?

[0, 1, 4]

300

What is the output of 'Python'[1:4]?

'yth'

300

What is the result of len([1, 2, 3, 4, 5]) and len({1, 2, 3, 4, 5})?

Both are 5

300

How would you reverse a list lst using slicing?

lst[::-1]

300

Give all examples of items that would categorize as False in python

False, 0 (int), 0.0 (double), "", [], {}, (), set(), None

300

How do you create a set comprehension to get squares of numbers from 1 to 5?

{x**2 for x in range(1, 6)}

400

What method would you use to check if a string contains only digits?

isdigit()

400

What is the difference between a list and a set in Python?

A list maintains order and allows duplicates, while a set is unordered and contains only unique elements

400

What will be the output of list(range(2, 10, 2))?

[2, 4, 6, 8]

400

Given the expression x = 0 or 5, what will be the value of x?

5 (due to lazy evaluation, Python returns the first truthy value)

400

What does the following list comprehension do: [x for x in range(10) if x % 2 == 0]?

It creates a list of all even numbers from 0 to 9

500

What is the difference between the find() and index() methods in Python strings?

find() returns -1 if the substring is not found, while index() raises a ValueError.

500

What is the output of {1, 2, 2, 3} | {2, 4, 6} and [1, 2, 3] + [4, 5]?

{1, 2, 3, 4, 6} for the set union, and [1, 2, 3, 4, 5] for list concatenation

500

How do you slice every other element from a list lst starting at index 1?

lst[1::2]

500

What does True and False or True evaluate to, and why?

True (evaluated as (True and False) or True → False or True → True)

500

What is the output of the dictionary comprehension {x: x**2 for x in range(3)}?

{0: 0, 1: 1, 2: 4}