06.0 Python‎ > ‎Python Notes‎ > ‎String Processing‎ > ‎

Tool Box for Sequential Data Types

In the Box the Phrase Project you will be investigating Strings and how to manipulate them. Python has 5 other types of built-in data types the can be managed the same way as a String. The skill set you will practice here will allow you to also manipulate: byte sequences, byte arrays, lists, tuples, range objects.

Objectives

The student will analyze string manipulation code and create docstrings and comments describing the codes intent. 
The student explore and use Help>Python Manuals to help them in creating their docstrings and comments. (hint: search the index for string, then look for methods )
The code will include:
  • single character from a string: [x]
  • a sub string: [start:stop]
  • negative subscripts(or index): [:-2]
  • string concatenation: + and *#
  • length of a string: len()
  • using a for loop to access one character at time
  • replacing one sub string for another sub string: .replace(this, that)
  • find the starting location of a sub string: .find(this)
  • divide a string in two about the first occurrence of a string: .partition(s)
  • place all words in a list: .split()
  • sort a list: .sort()
  • center a phrase: .center(#)
  • chr() and ord()

Program Description


Download the attached python file. Using docstrings and comments, document each function describing the intent of the code.
  • Completing CS Circles 7A will help you understand this code
  • Investigate each function by removing the comment # tag in the main()
  • change some of the phrases and numbers being used to see how the code output will change.
  • look at the 40 built in string methods available in Python

ċ
stringMethods.py
(4k)
M. A. Vandepoele,
14 Oct 2014, 06:44
Comments