Lecture06-lists-part1-3pp - 130923 Lists CMPUT 174 Lists A...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
13-09-23’ 1’ Lists CMPUT’174’ Lists ’A’list’is’a’sequence’of’values’ ’Wri?en’surrounded’by’square’brackets’ ie.’[0,1,2,3]’or’[“a”,’3,’5.6,”b”]’ ’Values’are’stored’in’order,’like’characters’in’ a’string’ ’Items’in’the’list’can’be’of’diFerent’types’ ±or’example,’the’second’list’above’contains’ strings,’ ints’and’floats’ Lists ’No’maximum’size’ ’Like’strings,’²rst’index’is’0’ ’A’list’with’ n ’values’has’indices’0,’1,’…,’n-1’ ’“-1”’can’also’serve’as’the’index’of’the’last’ item’ ’Unlike’strings,’lists’are’ mutable my_list[0] = “x” is’valid’ my_string[0] = “x” is’not’
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
13-09-23’ 2’ List Operators and Messages List Operators and Message Examples List Operators and Messages
Background image of page 2
13-09-23’ 3’ List Operators - more examples List’concatena\on:’adding’2’lists’together’to’get’a’larger’ list’ Mul\ple’concatena\on:’concatena\ng’mul\ple’copies’of’ the’same’list’ List Operators - more examples Python’ built-in func9ons can’be’used’on’lists:’minimum,’ maximum,’and’sum’of’elements’ Finding’the’length’(number’of’elements),’same’as’for’ strings’ in Operator VERY USEFUL ’Boolean’expression’for’checking’ membership’ value list expression VALUE’ in ’LIST’EXPRESSION’ True’if’the’element’is’in’ the’list.’False,’otherwise’
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
13-09-23’ 4’ in Operator The’ in ’operator’can’also’be’used’with’ Strings We can also use not in to formulate Boolean expressions What is the output? even=[2,4,6] even.extend([0]) print(even) odd=[1,3,5] name=[“odd”] odd.extend(name) print(odd) words=[“hello”,”Fred”,”bye”] if(words.pop()==“hello”): print(“x”) print(words) numbers=([1,3,5]+[7,9])*2 print(numbers) What is the output?
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 12

Lecture06-lists-part1-3pp - 130923 Lists CMPUT 174 Lists A...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online