week 3 - types Flashcards
string
sequence of characters that can be stored in a variable, immutable
string literal
string value specified in the source code of the program
sequence type
type that is a specified collection of objects ordered from left to right
position in sequence is called index
len()
function that returns number of elements in a sequence type
brackets []
used to index a sequence type
alphabet[0] returns…
A
alphabet[-1]
last character (Z)
how to update strings
assign an entirely new string, you can’t edit because its immutable
string concatenation
adding a new character at the end of a string
container
construct to group related values together and contain references to other objects instead of data
list
container created by sequence of variables or literals with brackets
element
list item
index
position of element in list, starting with 0
updating list elements
lists are mutable and can change through re-assignment
method
instructs object to preform some action, executed by specifying method name with “.” and object identifier
append.identifier(value)
adds value to end of list
pop.identifier(1)
removes element at index
remove.identifier(value)
removes first element that matches value
sequence type function
built in functions that operate on sequences like lists/strings
sequence type methods
methods built into class definitions of sequences like lists/strings
list.index(v)
find index of 1st element who’s value is v
list.count(v)
count occurrences of v in list
tuple
immutable collection of data, sequence type
made with paranthesis
when are tuples usually used?
when element position is important
named tuple
allows program to define a simple new data type that consists of named attributes