Noteaa
Noteaa
T7: |lists and str = sequences (ordered) of arbitrary values /characters from math importsorpi
* -> pi
|concatenated for str/list: [2.1, 3.2] + [7.8] -> [2.1, 3.2, 7.8]; repeated:
lrespectively
3 * [5] = [5, 5, 5] ||| “A”<“B”/“A”<“AA”/“AA”<“AB”/[1]<[2]/[1]<[1,0]/
[1,1,9]<[1,2,0] ||| len(‘’) == len([]) == 0
|slicing (numbers are indices): start( default = 0, included, doesnt
have to exist) :end(default to the end, excluded, doesnt have to
exist) :step(optional, default=1)
“programiz.pro”[-4:-2] -> .p / "abcdefghij"[2::3] -> “c ”
|list mutable bc value iself can be changed; str immutable
can assign new values to list: ls = [7, 9, 8] negation not
ls[1] = 11 >>>print(ls) -> [7, 11, 8]
| “8” + 2 INVALID/“8” + “2” VALID coming chin
I
Assertion
Error
T13: |collection type contains multiple values/sequence=ordered collection(ex:list,range,str);items numbered 0to N-1
|dictionary = mutable&iterable collection: map from set of keys to group of values, key-value pair = item
|can be written: dc={‘red’:3,’blue’:2} |access values: print(dc[‘red’]) -> 3
|dict: d1 = dict() same as d2 = {} |add item to dict w/ assignment: d1[‘bass’]=2 \ replace existing value: d1[‘bass’]+=1
|sequence=map from index i to value x[i] \dictionary generalizes this: map from arbitrary set(not ordered int) to values
|construct dict: 1.a=[[‘red’, 0], [‘blue’, 8]] >>> d=dict(a) 2.d=dict(red=0, blue=8) 3.keys=[‘red’, ‘blue’] f
d=dict.fromkeys(keys, 0) -> {'red': 0, 'blue': 0} |operators: 1.comparions (=, !=) item order dont matter 2.check key
present in dict: k in d 3.dict cant +,*,<=, <, >=, >, slices
hgg gyqy
T12: |method: function associated with type, name not global
|immutable values change only by assignment (with = ) e.g. y =
y.upper(); assignment works for all types of values
I |mutable can be changed by functions or methods (return
values might not be
expected)
I can also be modi ed
by assignment to index
C
read
y exp. e.g. x[7-2] += 3
removefirst
immutable types cant fog
versiontype
doesn't modifystr itself
only returns