11:HANDLING OF CHARACTER STRINGS

11.2.1, page number:180

In [3]:
inform=['m','a','d','u','r','a','i']
print "".join(inform)
madurai

11.3.1,page number:182

In [4]:
inform="Thiagaragar"
numb=int(input("No. Of Char To Print "))
print 'print format = %.0',numb,'s'
print inform[0:numb]
No. Of Char To Print 6
print format = %.0 6 s
Thiaga

11.4.1,page number:183

In [5]:
inform="Thiagaragar"
numb=int(input("No. Of Char To Print "))
print 'print format = %.0',numb,'s'
print inform[0:numb]
No. Of Char To Print 6
print format = %.0 6 s
Thiaga

11.5.1,page number:183

In [6]:
array1='Thiagarajar Engg'
array2=(array1 + '.')[:-1]
print "array1 = ",array1
print "array2 = ",array2
array1 =  Thiagarajar Engg
array2 =  Thiagarajar Engg

11.6.1,page number:184

In [7]:
userInput = raw_input("Enter Int: ")
if userInput.isdigit():
    print "Number = "+userInput
else:
    print userInput,"is not int type"
Enter Int: 8
Number = 8

11.7.1,page number:186

In [8]:
first="Thiagrajar"
second=first+" Engg."

print "first = ",first
print "second = ",second
first =  Thiagrajar
second =  Thiagrajar Engg.

11.8.1,page number:187

In [2]:
string1 = "Hello"
print "len of str is",len(string1)
string2 = " There"
print "string1+string2 is",string1+string2
 len of str is 5
string1+string2 is Hello There

11.12.1, page number:189

In [9]:
import array
i=20
size=0
str1 =[]
str2=[]
def readSize():
    global size
    size=int(input("Enter number of strings : "))
    if size<1 or size>i :
        readSize()
    return
def readArray():
    global size
    global str1
    print "Enter the Strings.."
    for k in range(0,size):
        m=raw_input()
        str1.append(m)
    return
def displayArray1():
    for index in range(0,size):
        print str1[index]
    return
def displayArray2():
    for index in range(0,size):
        print str2[index]
    return
def sortedArray():
    global str1
    global str2
    str2= sorted(str1)
    return

readSize()
readArray()
print "The unsorted array is.."
displayArray1()
sortedArray()
print "The sorted array is.."
displayArray2()
Enter number of strings : 6
Enter the Strings..
computer
page
diskette
eprom
binary
random
The unsorted array is..
computer
page
diskette
eprom
binary
random
The sorted array is..
binary
computer
diskette
eprom
page
random