Which methods are used to change the case of strings?
How do you create an empty list and an empty set in Python?
[] or list() for a list, and set() for a set.
How do you slice the first 3 elements of a list lst?
lst[:3]
What will False and True evaluate to?
False
What is list comprehension used for?
To create lists in a concise way
How would you access the last character of a string s?
s[-1]
What method is used to add an element to a list and to a set?
append() for a list, and add() for a set
What is the result of range(5)?
range(0, 5) (which is equivalent to [0, 1, 2, 3, 4]
What does False or (3 > 1) evaluate to?
True
What is the output of [x**2 for x in range(3)]?
[0, 1, 4]
What is the output of 'Python'[1:4]?
'yth'
What is the result of len([1, 2, 3, 4, 5]) and len({1, 2, 3, 4, 5})?
Both are 5
How would you reverse a list lst using slicing?
lst[::-1]
Give all examples of items that would categorize as False in python
False, 0 (int), 0.0 (double), "", [], {}, (), set(), None
How do you create a set comprehension to get squares of numbers from 1 to 5?
{x**2 for x in range(1, 6)}
What method would you use to check if a string contains only digits?
isdigit()
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
What will be the output of list(range(2, 10, 2))?
[2, 4, 6, 8]
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)
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
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.
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
How do you slice every other element from a list lst starting at index 1?
lst[1::2]
What does True and False or True evaluate to, and why?
True (evaluated as (True and False) or True → False or True → True)
What is the output of the dictionary comprehension {x: x**2 for x in range(3)}?
{0: 0, 1: 1, 2: 4}