Chapter 4 – Python String Operations Part 1

 
Step 1
 
Open any text editor (gedit,pico,vi,nano) then enter the following python script and save the file with .py extension.
 
#!/usr/bin/python
#Author : Jijo K Jose
 
print "\n————————————\nChapter 4 – String 1\n————————————\n"
 
a = raw_input("Enter any string : ")
print "%s contains %d character" %(a,len(a))
print "\nLast character of %s is : %s" %(a,a[len(a)-1])
print "\nFirst 3 characters are : %s" %(a[0:3])
print "\nEach Characters are…"
for ch in a:
print ch
b = raw_input("\nEnter second string : ")
if a==b:
print "\nStrings are equal"
else:
print "\nStrings are not equal"
 
print "\n————————————\n"
 
#END
 

Step 2
 
Change file permission to executable using chmod command.
 
Step 3
 
Execute the python file.
 
python-string-operation-4
 

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

Leave a Reply