rec10 - CS 177 Week 9 Recitation Slides Creating and...

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

View Full Document Right Arrow Icon
1 CS 177 Week 9 Recitation Slides Creating and Modifying Text
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 ANY QUESTIONS?
Background image of page 2
Text and String Like sound, text is usually processed in an array —a long line of characters Strings are defined with quote marks: Single quotes „ my string „ Double quotes “ my string “ Triple quotes “““ my string “““ Question: When triple quotes are used? 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Encoding for Strings Strings are just arrays of characters Characters are either encoded in ASCII (single byte) or unicode (2 bytes). ord(char): returns the ASCI value of char. Example: >>> str = “JES" >>> for char in str: ... print ord(char) 74 69 83 4
Background image of page 4
Backslash escape “\b”: backspace “\n”: newline “\t” : tab “\uXXXX”: unicode of XXXX 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
What is the output? >>> print "Good\nMorning“ >>>print "Bo\bok“ >>> print "Good\tMorning“ 6
Background image of page 6
Getting Parts of a String string[n] gives you the n th character in the string string[n:m] gives you the n th up to (but not including) the m th character. string[0:len(string)] is the whole string Example: >>> str = "mathematics“ >>> print str[4] e >>> print str[6] a 7
Background image of page 7

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

View Full DocumentRight Arrow Icon
Example continued >>> print str[:4] math >>> print str[4:] ematics >>> print str[:] mathematics 8
Background image of page 8
String Methods find(findstring) and find(findstring,start) and find(findstring,start,end)
Background image of page 9

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

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

This note was uploaded on 02/22/2012 for the course CS 177 taught by Professor Staff during the Fall '08 term at Purdue.

Page1 / 26

rec10 - CS 177 Week 9 Recitation Slides Creating and...

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

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