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
Q

named tuple

A

allows program to define a simple new data type that consists of named attributes

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

car.price
car.horsepower
what’s the name of the tuple?

A

car

27
Q

what must you do to use named tuples?

A

import namedtuple

28
Q

creating named tuples

A

car = namedtuple(‘car’, [‘make,’, ‘mode’, ‘price’])

29
Q

set

A

unordered collection of unique elements, sequential obj only

30
Q

does a set have postions/indeces?

A

NO

31
Q

can more than one element share the same value in a set?

A

NO

32
Q

set()

A

function to make a set, elements can be lists, tuples, strings, etc. used to make empty sets

33
Q

set literal

A

written using {}

34
Q

set.add()

A

places new elements into the set

35
Q

set.remove()

A

takes out specific element from set

36
Q

set.pop()

A

takes out random element from set

37
Q

set1.update(set2)

A

adds elements of set2 to set1

38
Q

set1.clear()

A

removes all elements from set

39
Q

set.intersection(set1, set2, set3)

A

returns new set only with elements in common between set and inserted sets

40
Q

set.union(set1, set2, set3)

A

returns new set with all unique elements between sets

41
Q

set.difference(set1, set2, set3)

A

only returns set elements not found in inserted sets

42
Q

set.symmetric_difference(setb)

A

returns elements only with elements once in either a or b

43
Q

max(list)

A

finds max value in list

44
Q

sum(list)

A

adds all numeric elements in list

45
Q

set.sort()

A

rearranges biggest to smallest

46
Q

string.split()

A

splits string into list, default delimiter is space

47
Q

dictionary

A

collection of key value pairs where you can quickly look up values if you know the key

48
Q

accessing certain key in dictionary

A

age[‘ellen’]

49
Q

list(), tuple()

A

conversion functions

50
Q

dict

A

object type for dictionary

51
Q

key

A

term located in dictionary that is associated with a value, immutable

52
Q

value

A

describes some data associated with key, ex: definition

53
Q

making a dictionary

A

players = {‘Messi’: 10, ‘Ronaldo’: 7}

54
Q

empty dictionary

A

{}

55
Q

accessing dictionary entries

A

index with specific key in brackets

56
Q

keyerror

A

runtime error

57
Q

adding new entry to end of dict

A

prices[‘banana’] = 4.00

58
Q

removing entries

A

del prices[‘papayas’]

59
Q

adding entries

A

dict[k] = v -> adds new key value pair

60
Q

numeric types

A

int and float, store data and support normal math operations

61
Q

mapping types

A

dict, container where each element is independent with no ordering or relation to other elements

62
Q

type conversion

A

convert between types

63
Q

implicit conversion

A

automatically made by interpreter, usually through operations

64
Q

int()

A

converts float to int without rounding, simply removes fractional part