Lec7StringsReview

Lec7StringsReview - Announcements: Remember that the test...

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

View Full Document Right Arrow Icon
Announcements: Remember that the test is Tuesday – review sheet posted, practice midterm now posted Extra office hours Monday 2-4pm (in my office) – Tuesday office hours canceled Today: def countChar(string) sum = 0 for i in range(len(string)): #- [0,1,2,…,len(string)-1] if (string[i] == ‘a’): sum = sum + 1 return sum def countChar(string) sum = 0 for ch in string: # - [‘h’,’e’,’l’,’l’,’o’] if ( ch == ‘a’): sum = sum + 1 return sum countChar(“hello”) walle = cTurtle.Turtle() walle.forward(100) Three ways to call functions: functionName(args) - function variableName.functionName(args) - method moduleName.functionName(args) - method string methods – variableName.functionName upper() – return a string that’s the same, but with all uppercase lower() – return a string that’s all lowercase capitalize() – return a string that has the first letter capitalized index(item) – returns the index of the first occurrence of the item, but it has an error if it is not found find(item) – returns the index of the first occurrence of the item, -1 if it is not found
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/27/2011 for the course CMPSC 8 taught by Professor Franklin during the Fall '09 term at UCSB.

Page1 / 3

Lec7StringsReview - Announcements: Remember that the test...

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

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