Chapter 5 – Python String Operations Part 2

Step 1
Open any text editor (gedit,pico,vi,nano) then enter the following python script and save the file with .py extension.
#Author : Jijo K Jose
print "\n————————————\nChapter 5 – String 2\n————————————\n"
import string
a = raw_input("Enter any string : ")
print "%s contains %d character\n" %(a,len(a))
b = string.upper(a)
c = a.lower()
d = a.capitalize()
e = string.capwords(a)
print "%s in different forms are :"
print b;
print c;
print d;
print e;
print "\nSplit function result\n———————————————"
f = a.split()
print f
print "\nJoin function result\n———————————————"
g = string.join(f)
print g
print "\n————————————\n"


Step 2
Change file permission to executable using chmod command.
Step 3
Execute the python file.



You can leave a response, or trackback from your own site.

Leave a Reply