Sequence Types Flashcards

1
Q

Containers for collections of objects ordered by position in the sequence, where the first object has an index of 0 and subsequent elements have indices 1, 2, etc.

A

Sequence Types

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

What are all the sequence types ?

A

String, list, and tuples.

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

What are all the sequence-type methods ?

A

len()
+
min()
max()
sum()
index(val)
count(val)
append()
pop()
remove()

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

What does the method list.count(val) do ?

A

Count the number of occurrences of the value val in the list.

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

What does the method list.index(val) do ?

A

Find the index of the first element in the list whose value matches val.

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

Instructs an object to perform some action, and is executed by specifying the ___ name following a “.” symbol and an object.

A

Method

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

Which sequence-type containers are mutable ?

A

Lists & dicts

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

Which sequence-type containers are immutable ?

A

Strings and Tuples

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

What is the syntax to create a list ?

A

my_list = [ ]

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

How to access a sequence type element ?

A

my_sequence[i]
i = index

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

What is the syntax to create a tuple ?

A

my_tuple = (‘abc’)

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

Which sequence type allows the programmer to define a new simple data type that consists of named attributes ?

A

named tuple

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

Syntax to create a new named tuple Dog that has the attributes name, breed, and color.

A

Dog = namedtuple([‘name’, ‘gender’, ‘color’])

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

Create a new dog object called ‘Boston Terrier’ where name is ‘Camy’, gender is ‘female’, and color is ‘brown and white’.

A

Camy = Dog(‘Camy’, ‘Female’, ‘Brown and white’)

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

How to access a named tuple data object’s attributes ?

A

object_name.attribute_name
Ex) Camy.color

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

String

A

Sequence type used for text.

17
Q

List

A

Sequence type: A mutable container with ordered elements.

18
Q

Tuple

A

Sequence type: An immutable container with ordered elements.

19
Q

String

A

Sequence type: Used for text.