Friday, September 23, 2011

Python String List

#To print a list of numbers
print range(11)
numlist = range(5)
print "I am printing numlist populated by range method", numlist
print "Here I am printing values starting from 1st position",range(1,5)
print "Printing values starting from 1st position i+2",range(1,11,2)
strlist1 = ['Bala','subramaniam','Natarajan']
print "I am printing the string list1", strlist1
print "Reversing string list1", strlist1
strlist2 = ['Bala','Revathi']
print "I am printing the string list2", strlist2
print "I am printing the appended string list1", strlist1
print strlist1[3][1]
print "I am printing the extended string list1", strlist1

#To print a log_file
import string

log_file = "20110923 1110 80 404 vaka.html"
print log_file
print "The type of log_file is : ", type(log_file)
print string.split(log_file)
log_file2 = string.split(log_file)
print "The type of log_file2 is: ", type(log_file2)
print "The date in our log file is : ", log_file2[0]
log_file3 = string.join(log_file2)
print "The type of log_file3 is : ", type(log_file3)

No comments:

Post a Comment