diff options
author | Puneeth Chaganti | 2010-11-05 21:42:20 +0530 |
---|---|---|
committer | Puneeth Chaganti | 2010-11-05 21:42:20 +0530 |
commit | 8e77886958776b482ac2e634f9bf5e421ba5866f (patch) | |
tree | 494af5c08ba18355fddcd0277d69425a924c9a52 | |
parent | 136fffb18cd9799519b096778d7249c1ed2359fa (diff) | |
download | st-scripts-8e77886958776b482ac2e634f9bf5e421ba5866f.tar.gz st-scripts-8e77886958776b482ac2e634f9bf5e421ba5866f.tar.bz2 st-scripts-8e77886958776b482ac2e634f9bf5e421ba5866f.zip |
Changes to manipulating strings, based on review.
-rw-r--r-- | manipulating-strings/script.rst | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/manipulating-strings/script.rst b/manipulating-strings/script.rst index 50d5e32..c991dda 100644 --- a/manipulating-strings/script.rst +++ b/manipulating-strings/script.rst @@ -34,9 +34,6 @@ In this tutorial we shall learn to manipulate strings, specifically slicing and reversing them, or replacing characters, converting from upper to lower case and vice-versa and joining a list of strings. -.. #[punch: reversed returns an iterator. should we still teach it?] - - We have an ``ipython`` shell open, in which we are going to work, through out this session. @@ -69,9 +66,8 @@ the tutorial. So, we need to check if the first three characters of the given string exists in the variable ``week``. -As, with any of the string data-types, strings can be sliced into -.. #[Amit: Sequence data type???] -sub-strings. To get the first three characters of s, we say, +As, with any of the sequence data-types, strings can be sliced into +sub-strings. To get the first three characters of s, we say, :: @@ -84,7 +80,7 @@ As we already know, the last element of the string can be accessed using ``s[-1]``. Following is an exercise that you must do. -.. #[Amit: I don't know I am not sure about the sentence formation.] + %%1%% Obtain the sub-string excluding the first and last characters from the string s. @@ -129,7 +125,7 @@ So, we obtain the reverse of s, by simply saying, :: s[::-1] -.. #[amit: I think using reversed in not required after this] + Now, to check if the string is ``s`` is palindromic, we say :: @@ -152,16 +148,15 @@ Let's try it out. s +As you can see, s has not changed. It is because, ``upper`` returns a +new string. It doesn't change the original string. + +:: + s.lower() s.lower() == s.lower()[::-1] -Note that these methods, do not change the original string, but return -a new string. - -.. #[amit: I wish we could include this right when s.upper() is used so -.. that it is clear] - Following is an exercise that you must do. %%2%% Check if ``s`` is a valid name of a day of the week. Change the @@ -176,8 +171,11 @@ Please, pause the video here. Do the exercise and then continue. s.lower()[:3] in week -.. #[amit: May be a sentence or two about what our original problem was and -.. how this helps in solving it. One can loose the flow.] + +So, as you can see, now we can check for presence of ``s`` in +``week``, in whichever format it is present -- capitalized, or all +caps, full name or short form. + We just convert any input string to lower case and then check if it is present in the list ``week``. |