Reading about strings

posted by: Ms. Martin 25 April 2011 No Comment

Knowing how to read and interpret documentation is a terrifically useful skill that will help support your independent learning goals.  It’s important to me that you get some experience reading technical documents in this class.  I would like you to start by reading this book chapter and answering a few questions about it on a separate sheet of paper to turn in.  Make sure you are trying things at the shell as you go!

  1. What is a string?
  2. How would you figure out how many characters a particular string has in it?
  3. How would you attach two strings together and display them as one?
  4. In what context might string slicing be useful (think carefully of software you’ve used)?
  5. What is a method?
  6. How are methods different from functions?
  7. Read about different string methods in the official Python documentation.  Note that parameters in brackets are optional.  For example, when you call the method str.replace(oldnew[, count]), you must specify the string to replace (old), what to replace it with (new), and you can optionally specify a number of the old string to replace.  For example:
    "banana".replace("a", "o") will give you back "bonono" and "banana".replace("a", "o", 2) will give you back "bonona"
    Find the three methods you think would be the most useful and describe them in detail.  How would they be useful?
  8. Complete exercise 12 (on the computer).  You can get information on built-in functions here.

Done?  Check out lists!

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>