108HL13 - Lists Lecture 13, Week 5 February 7, 2011...

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

View Full Document Right Arrow Icon
Lists Lecture 13, Week 5 February 7, 2011 CSC108H1S Velian Pandeliev 1 Monday, February 7, 2011
Background image of page 1

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

View Full DocumentRight Arrow Icon
Announcements 2 Quiz 2 on Wednesday will cover what we've learned up to the end of last week. Quiz 2 will start at 10:15 and will last until 10:30. Anyone arriving after 10:20 will not be able to write the quiz and will receive 0 on it. Assignment 1 is due Friday. We will not be answering any questions from Thursday 10 pm - Friday 10 pm Read the discussion board for commonly asked questions. I have of±ce hours tomorrow. Monday, February 7, 2011
Background image of page 2
3 Recap of Lecture 12 Monday, February 7, 2011
Background image of page 3

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

View Full DocumentRight Arrow Icon
String Methods 4 Some general operators apply to strings (such as > , < , + ), and strings can also be parameters of some general functions (like len() ). However, there are operations that only apply to strings. They are deFned in special functions called methods . Strings own their methods like modules own their functions. They are called the same way: string_variable . method () Monday, February 7, 2011
Background image of page 4
Calling Methods vs Functions 5 len( stringname ) # fine stringname. len() # wrong stringname.methodname () # fine methodname ( stringname ) # wrong If an operation is only relevant to one type of object, it's de±ned as a method for that object. If an operation is relevant to more than one type of object (lists have lengths too!), it is de±ned as a function and the object is passed to it as a parameter. Monday, February 7, 2011
Background image of page 5

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

View Full DocumentRight Arrow Icon
String Methods 6 s.upper() - all characters in s to uppercase s.lower() - all characters in s to lowercase s.capitalize() - frst character uppercase s.find(a) - index oF frst occurrence oF a in s s.replace(a,b) - replace all occurrences oF a in s with b s.count(a) - number oF occurrences oF a in s s.startswith(a) - True iFF s starts with a s.split(a) - list oF 'words' separated by a Monday, February 7, 2011
Background image of page 6
7 CodeLab Moments Monday, February 7, 2011
Background image of page 7

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

View Full DocumentRight Arrow Icon
Concatenation 8 Write an expression whose value is the concatenation of the three str values associated with name1 , name2 , and name3 , separated by commas. So if name1 , name2 , and name3 , were (respectively) "Neville", "Dean", and "Seamus", your expression's value would be "Neville,Dean,Seamus". '"%s, %s, %s"' % (name1, name2,
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 30

108HL13 - Lists Lecture 13, Week 5 February 7, 2011...

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

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