Module 4: Strings and Lists are iterables Flashcards

1
Q

A _______ is a collection of items in some order.

A

sequence

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

A string is a ______ meaning it is an ordered collection of other values.

A

sequence

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

Access characters of a string one at a time using _______.

A

bracket operator

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

expression in [ ] brackets is _______ and starts at ______.

A

index, 0

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

value of an index must be _______.

A

integer

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

______ is a built in function that returns number of characters in a string.

A

len(stringname)

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

to get last digit of word from index use [ ______ ] or [ ______ }

A
  1. first: length = len(fruit)
    last length-1
  2. [-1]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A _____ is a segment of a string

A

slice

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

select a slice using [ _______ ]

A

n:m
:m or n:

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

A _______ is a pattern that starts at the beginning, select each character in turn, do something to it, and continue until the end.

A

traversal

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

strings are _______ meaning you cannot change an existing string and cannot use [ ] on the left side of assignment.

A

immutable

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

A ______ is the pattern of computation of traversing a sequence and returning when we find what we are looking for.

A

search

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

A list is a sequence of _______. In a string values are _______, in a list they are _______.

A

values, characters, any/elements/items

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

empty list is given by ______

A

[ ]

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

variables can be ________ list values

A

assigned

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

syntax for accessing elements of a list is ______ as for accessing characters of a string

A

the same

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

unlike strings, lists are ______, meaning they can be _______

A

mutable, changed

18
Q

A ______ is commonly used to traverse the elements of a list

19
Q

range(n) returns a sequence of n number from ____ to ____

20
Q

A for loop over an _____ never runs the body.

A

empty list

21
Q

______ takes a value and mutates the list, adding the new element to the end

A

listname.append(value)

22
Q

______ takes a list and mutates the first list, appending all the values in the second list to it.

A

firstlistname.extend(secondlistname)

23
Q

_____ returns another list containing all the same items. It takes ________ arguments.

A

firstlistname.copy()
no

24
Q

______ modifies the list and returns the element that was removed. if an index isnt provided it deletes and returns the last element.

A

firstlistname.pop(#)

25
use _____ to convert from a string to a list of characters
list(nameofstring)
26
use ______ to break a string into words
firstlistname.split(delimiter) can use ( ) instead where it will split at spaces
27
______ is an optional argument that specifies which characters to use as word boundaries
delimiter
28
_________ takes a list of strings and concatenates the elements. must invoke it on the delimiter and pass the list as a parameter.
delimiter.join(firstlistname)
29
______ data types cannot be changed and include _____, ______, _______.
immutable, int, float, str
30
use _____ to check whether two variables refer to the same object
is
31
a ________ is the association of a variable with an object
reference
32
if an aliased object is mutable, changes made to one alias will _______
affect the other
33
a tuple is like a list but is _______
immutable
34
strings, lists, and range objects are all ________
iterables
35
The first value for index is _______ and the last is _______.
0 length - 1
36
the len function returns type _______.
int
37
To create a boolean expression using in write _______, ________, ________.
value, in, iterable such as str or list
38
Use [_____:______:______] to go through a list/string while selecting only certain values.
start stop step
39
in an index _______ returns the last value
-1
40
Create a tuple using _______ brackets. For a tuple with only one object add a _______ after the object. Can convert _______ or _______ to a tuple by _______.
round ( ) , string list tuple("string") or tuple([list])
41
compared to a list which has _______ argument, a tuple has ________ argument.
1 many