Python LIst

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/29

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:37 PM on 7/15/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

30 Terms

1
New cards

Syntax for creating a list in Python?

list_name = [] or list_name = list()

2
New cards

Is a Python list mutable or immutable?

mutable

3
New cards

Does a Python list allow duplicate values?

Yes, Python lists allow duplicate values.

4
New cards

What data types can a Python list have?

A Python list can contain any Python object, including mixed data types.

5
New cards

Please explain the difference between is vs ==?

== checks for equality (value) while is checks for identity (reference to the same object in memory).

6
New cards

How do you add an element to the start of a Python list?

Use the .insert() method, passing in the index and the value. Ex: list_name.insert(0, value)

7
New cards

How do you insert an element into a specific index in a Python list?

Use the .insert() method, passing in the index and the value. Ex: list_name.insert(index, value)

8
New cards

How do you add an element to the end of a Python list?

Use the .append() method passing the value to be added. Ex: list_name.append(value)

9
New cards

What is the difference between .append() and .extend() methods for Python list?

.append() adds a specified element to the end of the list, whereas .extend() adds an iterable (like another list) to the end of the list.

10
New cards

How do you update an existing element in a Python list?

Use brackets after the list name with the index and the value. Ex: list_name[index] = new_value

11
New cards

How do you remove an element in a Python list while returning its value?

Use pop() method. Ex: list_name.pop(index)

12
New cards

How do you remove an element in Python without returning its value?

Use remove() method (removes only the first occurrence) or the del keyword. Ex: list_name.remove(value) or del list_name[index]

13
New cards

How do you access the first element in a Python list?

Use list name with brackets. Ex: list_name[0]

14
New cards

How do you access an element at a specific index in a Python list?

Use list name with brackets. Ex: list_name[index]

15
New cards

How do you access an element at the end of a Python list?

Use list name with brackets. Ex: list_name[-1]

16
New cards

How do you find the index of a value in a Python list?

Use the .index() method, which returns the first occurrence of the specified value. Ex: list_name.index(value)

17
New cards

How do you check if an element is present in a Python list?

Use the 'in' operator. Ex: if value in list_name:

18
New cards

How do you check if an element is not in a Python list?

Use 'not in'. Ex: if value not in list_name:

19
New cards

How do you find the length of a Python list?

Use the len() function. Ex: len(list_name)

20
New cards

How do you iterate through a list in Python?

You can use a for loop, range, or while, but a for loop is the most common. Ex: for i in list_name:

21
New cards

How do you iterate through a list in Python with both the index and value?

Use the enumerate() function. Ex: for index, value in enumerate(list_name):

22
New cards

How do you remove all elements in a list in Python?

Use the .clear() method. Ex: list_name.clear()

23
New cards

How do you delete a list in Python entirely?

Use the del keyword. Ex: del list_name

24
New cards

How do you sort a list in Python?

You can either use .sort() or sorted()

25
New cards

What is the difference between sort() and sorted() list methods?

.sort() modifies the original list in-place and returns None, while sorted() returns a brand new sorted list without modifying the original.

26
New cards

What types of list can be sorted in Python?

Lists containing comparable data types.

27
New cards

How do you copy a list in Python?

Use the .copy() method or list() constructor. Ex: new_list = list_name.copy() or new_list = list(list_name)

28
New cards

How do you get a specific range of values in a list in Python?

Use slice notation. Ex: list_name[starting_index : ending_index]

29
New cards

How do you test if a list is empty in Python?

Use an if statement combined with 'not'. Ex: if not list_name:

30
New cards

How do you make a new list in Python with list comprehension?

Use the syntax: newlist = [expression for item in iterable if condition]. Ex: newlist = [x for x in range(10)]