diff options
author | Puneeth Chaganti | 2010-10-10 13:44:51 +0530 |
---|---|---|
committer | Puneeth Chaganti | 2010-10-10 13:44:51 +0530 |
commit | f9716ed61e783585b036ae18d67c64a8bfc36b30 (patch) | |
tree | a4e49b3cb7dccb78fcf1918a1d421d6b909bf4ef | |
parent | 0894afa11beac170154edff37bef6e810fe2d9f3 (diff) | |
parent | 0f24b97fba8b5b1a11d9e94ddc03e5183ae4e19f (diff) | |
download | st-scripts-f9716ed61e783585b036ae18d67c64a8bfc36b30.tar.gz st-scripts-f9716ed61e783585b036ae18d67c64a8bfc36b30.tar.bz2 st-scripts-f9716ed61e783585b036ae18d67c64a8bfc36b30.zip |
Merged heads.
-rw-r--r-- | manipulating-strings/script.rst | 102 |
1 files changed, 85 insertions, 17 deletions
diff --git a/manipulating-strings/script.rst b/manipulating-strings/script.rst index eac5b25..1ba16d1 100644 --- a/manipulating-strings/script.rst +++ b/manipulating-strings/script.rst @@ -1,18 +1,40 @@ -======== - Script -======== +.. Objectives +.. ---------- -{{{ show the welcome slide }}} +.. By the end of this tutorial, you will be able to -Welcome to this tutorial on manipulating strings. +.. 1. Slice strings and get sub-strings out of them +.. #. Reverse strings +.. #. Replace characters in strings. +.. #. Convert to strings to upper or lower case +.. #. joining a list of strings + +.. Prerequisites +.. ------------- + +.. 1. getting started with strings +.. #. getting started with lists +.. #. basic datatypes + +.. Author : Puneeth + Internal Reviewer : + External Reviewer : + Checklist OK? : <put date stamp here, if OK> [2010-10-05] + +Script +------ + +{{{ Show the slide containing title }}} + +Hello Friends. Welcome to this tutorial on manipulating strings. {{{ show the slide with outline }}} 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 +upper to lower case and vice-versa and joining a list of strings. -#[punch: reversed returns an iterator. should we still teach it?] +.. #[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. @@ -59,8 +81,12 @@ not included. As we already know, the last element of the string can be accessed using ``s[-1]``. -%%1%% Pause the video here and obtain the sub-string excluding the -first and last characters from the string. +Following is an exercise that you must do. + +%%1%% Obtain the sub-string excluding the first and last characters +from the string. + +Please, pause the video here. Do the exercise(s) and then continue. :: @@ -131,10 +157,13 @@ Let's try it out. Note that these methods, do not change the original string, but return a new string. -a%% %% Pause the video here, and finish the problem of checking if -``s`` is a valid name of a day of the week and then resume the -video. Change the solution to this problem, to include forms like, -SAT, SATURDAY, Saturday and Sat. +Following is an exercise that you must do. + +%%2%% Check if ``s`` is a valid name of a day of the week. Change the +solution to this problem, to include forms like, SAT, SATURDAY, +Saturday and Sat. + +Please, pause the video here. Do the exercise and then continue. :: @@ -160,20 +189,59 @@ method of strings. email = email.replace("[at]", "@") print email -%%1%% Pause the video here and replace the ``[dot]`` with ``.`` and then -resume the video. +Following is an exercise that you must do. + +%%3%% Replace the ``[dot]`` with ``.`` + +Please, pause the video here. Do the exercise and then continue. :: email = email.replace("[dot]", ".") print email +Now, let's look at another interesting problem where we have a list of +e-mail addresses and we wish to obtain one long string of e-mail +addresses separated by commas or semi-colons. + +:: + + email_list = ["info@fossee.in", "enquiries@fossee.in", "help@fossee.in"] + + +Now, if we wish to obtain one long string, separating each of the +email id by a comma, we use the join operator on ``,``. + +:: + + email_str = ", ".join(email_list) + print email_str + +Notice that the email ids are joined by a comma followed by a space. + +Following is an exercise that you must do. + +%%3%% From the email_str that we generated, change the separator to be +a semicolon instead of a comma. + +Please, pause the video here. Do the exercise and then continue. + +:: + + email_str = email_str.replace(",", ";") That brings us to the end of the tutorial. {{{ show summary slide }}} In this tutorial, we have learnt how to get substrings, reverse -strings and a few useful methods, namely upper, lower and replace. +strings and a few useful methods, namely upper, lower, replace and +join. + +{{{ Show the "sponsored by FOSSEE" slide }}} + +This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India + +Hope you have enjoyed and found it useful. +Thank you! -Thank You! |