# 108HL12 - String Methods Lecture 12 Week 4 February 4 2011...

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

String Methods Lecture 12, Week 4 February 4, 2011 CSC108H1S Velian Pandeliev 1 Saturday, February 5, 2011

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

View Full Document
Announcements 2 Quiz 2 is on Wednesday. It will cover what we'll learned up to the end of this week. Quiz 2 will start promptly 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. Saturday, February 5, 2011
3 Recap of Lecture 11 Saturday, February 5, 2011

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

View Full Document
Strings 4 A sequence of characters in Python is called a string . A string is how Python represents text. We can ask for the length of any string by calling built-in function len( string ) . >>> len('Hello World') >>> 11 Saturday, February 5, 2011
Strings Can Be Indexed 5 Strings are sequences of characters. Each character of a string is numbered with an index : character H e l l o ! index 0 1 2 3 4 5 NOTE: Indexing in strings starts with 0, not 1!! Individual characters can be obtained using the syntax: variable_name [ index ] Saturday, February 5, 2011

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

View Full Document
The Other Loop 6 The while loop repeats a sequence of statements until a condition is met. There is another loop in Python which is used to perform the same operation on each element in a collection: the for loop. The syntax for the for loop is as follows: for variable_name in collection : statement1 statement2 ... Saturday, February 5, 2011
for Loop 7 Let's try the for loop on a collection of characters (a string): for x in 'Hello World!': print x This means: "Take every element in collection 'Hello World!' in turn, assign it to variable x , and print it to the screen. Saturday, February 5, 2011

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/25/2011 for the course CSC 108 taught by Professor Gries during the Spring '08 term at University of Toronto.

### Page1 / 25

108HL12 - String Methods Lecture 12 Week 4 February 4 2011...

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

View Full Document
Ask a homework question - tutors are online