Lists and Boolean Flashcards

1
Q

What is the syntax for creating a list?

A

my_list = [1, 2, 3].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to add an item to the end of a list?

A

Use .append(item) (e.g., my_list.append(4)[1, 2, 3, 4]).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to combine two lists?

A

Use .extend() or + (e.g., [1,2].extend([3,4])[1,2,3,4]).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to insert an item at a specific index?

A

Use .insert(index, item) (e.g., [1,3].insert(1,2)[1,2,3]).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to remove the first occurrence of a value?

A

Use .remove(value) (e.g., [1,2,2].remove(2)[1,2]).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to remove and return an item by index?

A

Use .pop(index) (defaults to last item if no index is provided).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to sort a list in-place?

A

Use .sort() (e.g., [3,1,2].sort()[1,2,3]).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to reverse a list in-place?

A

Use .reverse() (e.g., [1,2,3].reverse()[3,2,1]).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is list slicing syntax?

A

list[start:end:step] (e.g., [1,2,3,4][1:3][2,3]).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to create a list with list comprehension?

A

[x*2 for x in range(3)][0, 2, 4].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between [1,2] + [3] and .append(3)?

A

+ creates a new list; .append() modifies the original.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a boolean value?

A

True or False (capitalized).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What values are considered falsy in Python?

A

0, '', None, [], {}, (), False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the output of bool('Hello')?

A

True (non-empty strings are truthy).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the output of bool([])?

A

False (empty lists are falsy).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to check if a list contains a value?

A

Use in (e.g., 2 in [1,2,3]True).

17
Q

What does all([True, 1, 'non-empty']) return?

A

True (checks if all elements are truthy).

18
Q

What does any([False, 0, 'text']) return?

A

True (checks if any element is truthy).

19
Q

What is short-circuit evaluation?

A

Stops evaluating expressions early (e.g., False and ...False).

20
Q

How to negate a boolean?

A

Use not (e.g., not TrueFalse).