{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture06-lists-part1-3pp

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

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

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’ﬂoats’ 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’

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

View Full Document
13-09-23’ 2’ List Operators and Messages List Operators and Message Examples List Operators and Messages
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’

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

View Full Document
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?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern