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

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

View Full Document Right Arrow Icon
String Methods Lecture 12, Week 4 February 4, 2011 CSC108H1S Velian Pandeliev 1 Saturday, February 5, 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 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
Background image of page 2
3 Recap of Lecture 11 Saturday, February 5, 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
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

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

Page1 / 25

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

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

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