Module 4: Strings and Lists are iterables Flashcards
A _______ is a collection of items in some order.
sequence
A string is a ______ meaning it is an ordered collection of other values.
sequence
Access characters of a string one at a time using _______.
bracket operator
expression in [ ] brackets is _______ and starts at ______.
index, 0
value of an index must be _______.
integer
______ is a built in function that returns number of characters in a string.
len(stringname)
to get last digit of word from index use [ ______ ] or [ ______ }
- first: length = len(fruit)
last length-1 - [-1]
A _____ is a segment of a string
slice
select a slice using [ _______ ]
n:m
:m or n:
A _______ is a pattern that starts at the beginning, select each character in turn, do something to it, and continue until the end.
traversal
strings are _______ meaning you cannot change an existing string and cannot use [ ] on the left side of assignment.
immutable
A ______ is the pattern of computation of traversing a sequence and returning when we find what we are looking for.
search
A list is a sequence of _______. In a string values are _______, in a list they are _______.
values, characters, any/elements/items
empty list is given by ______
[ ]
variables can be ________ list values
assigned
syntax for accessing elements of a list is ______ as for accessing characters of a string
the same
unlike strings, lists are ______, meaning they can be _______
mutable, changed
A ______ is commonly used to traverse the elements of a list
for loop
range(n) returns a sequence of n number from ____ to ____
0 to n-1
A for loop over an _____ never runs the body.
empty list
______ takes a value and mutates the list, adding the new element to the end
listname.append(value)
______ takes a list and mutates the first list, appending all the values in the second list to it.
firstlistname.extend(secondlistname)
_____ returns another list containing all the same items. It takes ________ arguments.
firstlistname.copy()
no
______ modifies the list and returns the element that was removed. if an index isnt provided it deletes and returns the last element.
firstlistname.pop(#)
use _____ to convert from a string to a list of characters
list(nameofstring)
use ______ to break a string into words
firstlistname.split(delimiter)
can use ( ) instead where it will split at spaces
______ is an optional argument that specifies which characters to use as word boundaries
delimiter
_________ 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)
______ data types cannot be changed and include _____, ______, _______.
immutable, int, float, str
use _____ to check whether two variables refer to the same object
is
a ________ is the association of a variable with an object
reference
if an aliased object is mutable, changes made to one alias will _______
affect the other
a tuple is like a list but is _______
immutable
strings, lists, and range objects are all ________
iterables
The first value for index is _______ and the last is _______.
0
length - 1
the len function returns type _______.
int
To create a boolean expression using in write _______, ________, ________.
value, in, iterable such as str or list
Use [_____:______:______] to go through a list/string while selecting only certain values.
start
stop
step
in an index _______ returns the last value
-1
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])
compared to a list which has _______ argument, a tuple has ________ argument.
1
many