week 3 - types Flashcards

1
Q

string

A

sequence of characters that can be stored in a variable, immutable

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

string literal

A

string value specified in the source code of the program

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

sequence type

A

type that is a specified collection of objects ordered from left to right

position in sequence is called index

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

len()

A

function that returns number of elements in a sequence type

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

brackets []

A

used to index a sequence type

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

alphabet[0] returns…

A

A

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

alphabet[-1]

A

last character (Z)

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

how to update strings

A

assign an entirely new string, you can’t edit because its immutable

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

string concatenation

A

adding a new character at the end of a string

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

container

A

construct to group related values together and contain references to other objects instead of data

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

list

A

container created by sequence of variables or literals with brackets

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

element

A

list item

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

index

A

position of element in list, starting with 0

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

updating list elements

A

lists are mutable and can change through re-assignment

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

method

A

instructs object to preform some action, executed by specifying method name with “.” and object identifier

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

append.identifier(value)

A

adds value to end of list

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

pop.identifier(1)

A

removes element at index

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

remove.identifier(value)

A

removes first element that matches value

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

sequence type function

A

built in functions that operate on sequences like lists/strings

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

sequence type methods

A

methods built into class definitions of sequences like lists/strings

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

list.index(v)

A

find index of 1st element who’s value is v

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

list.count(v)

A

count occurrences of v in list

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

tuple

A

immutable collection of data, sequence type
made with paranthesis

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

when are tuples usually used?

A

when element position is important

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
named tuple
allows program to define a simple new data type that consists of named attributes
26
car.price car.horsepower what's the name of the tuple?
car
27
what must you do to use named tuples?
import namedtuple
28
creating named tuples
car = namedtuple('car', ['make,', 'mode', 'price'])
29
set
unordered collection of unique elements, sequential obj only
30
does a set have postions/indeces?
NO
31
can more than one element share the same value in a set?
NO
32
set()
function to make a set, elements can be lists, tuples, strings, etc. used to make empty sets
33
set literal
written using {}
34
set.add()
places new elements into the set
35
set.remove()
takes out specific element from set
36
set.pop()
takes out random element from set
37
set1.update(set2)
adds elements of set2 to set1
38
set1.clear()
removes all elements from set
39
set.intersection(set1, set2, set3)
returns new set only with elements in common between set and inserted sets
40
set.union(set1, set2, set3)
returns new set with all unique elements between sets
41
set.difference(set1, set2, set3)
only returns set elements not found in inserted sets
42
set.symmetric_difference(setb)
returns elements only with elements once in either a or b
43
max(list)
finds max value in list
44
sum(list)
adds all numeric elements in list
45
set.sort()
rearranges biggest to smallest
46
string.split()
splits string into list, default delimiter is space
47
dictionary
collection of key value pairs where you can quickly look up values if you know the key
48
accessing certain key in dictionary
age['ellen']
49
list(), tuple()
conversion functions
50
dict
object type for dictionary
51
key
term located in dictionary that is associated with a value, immutable
52
value
describes some data associated with key, ex: definition
53
making a dictionary
players = {'Messi': 10, 'Ronaldo': 7}
54
empty dictionary
{}
55
accessing dictionary entries
index with specific key in brackets
56
keyerror
runtime error
57
adding new entry to end of dict
prices['banana'] = 4.00
58
removing entries
del prices['papayas']
59
adding entries
dict[k] = v -> adds new key value pair
60
numeric types
int and float, store data and support normal math operations
61
mapping types
dict, container where each element is independent with no ordering or relation to other elements
62
type conversion
convert between types
63
implicit conversion
automatically made by interpreter, usually through operations
64
int()
converts float to int without rounding, simply removes fractional part