Automate The boring stuff with python (Chapter 4 Lists)

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is the difference between lists and tuples ?

Lists are mutable; they can have values added, removed, or changed. Tuples are immutable; they cannot be changed at all. Also, tuples are written using parentheses, (and), while lists use the square brackets, [ and].

What are the operators for list concatenation and list replication ?

The operator for list concatenation is +, while the operator for replication is *. (This is the same as for strings.)

How do you type the tuple value that has just the integer value 42 in it ?

(42,) (The trailing comma is mandatory.)

Name a few ways that list values are similar to string values.

Both lists and strings can be passed to len(), have indexes and slices, be used in for loops, be concatenated or replicated, and be used with the in and not in operators.

How would you assign the value 'hello' as the third value in a list stored in a variable named spam ? (Assume spam contains [2,4,6,8,10].) For the following three questions, let's say spam contains the list ['a','b','c','d'].

Spam [2] = 'hello'

What are two ways to remove values from a list ?

The del statement and the remove() list method are two ways to remove values from a list.

What is [ ] ?

The empty list value, which is a list value that contains no items. This is similar to how ' ' is the empty string value.

How can you get the tuple form of a list value ? How can you get the list form of a tuple value ?

The tuple() and list() functions, respectively.

Variables that "contain" list values don't actually contain lists directly. What do they contain instead ?

They contain references to list values.

What is the difference between copy.copy() and copy.deepcopy() ?

They copy.copy() function will do a shallow copy of a list, while the copy.deepcopy() function will do a deep copy of a list. That is, only copy.deepcopy() will duplicate any lists inside the list.

What is the difference between the append() and insert() list methods ?

While append() will add values only to the end of a list, insert() can add them anywhere in the list.


Conjuntos de estudio relacionados

English IV Part 2 - Unit 4 - Lesson 1, 2, 3, AND 4 Quizzes

View Set

Chapter 25: Addiction and Substance Related Disorders

View Set

Chapter 9: The Flow of Food: Service

View Set

Chapter 18 - Governmental Entities: Special Funds and Governmentwide Financial Statements

View Set

Module 11: Database, Chapter 11 - Databases,

View Set

insurance exam problems to review

View Set