st='Programming'
print 'The string is %s' %st
st='Hello World'
print 'The line is :'
print st
strin='Welcome to python'
for i in strin:
print i,
str1='Programming'
len1=len(str1)
print 'The length of the string is ',len1
str2=str1
print 'First string is %s and copied string is %s' %(str1,str2)
str3='Computer'
if str1==str3:
print 'Both strings are equal'
elif str1<str2:
print 'First string is lesser than second string'
else:
print 'First string is greater than second string'
tempstr=' with C'
str1=str1+tempstr
print 'The concated string is ',str1
def strlength(str1):
count=0
for i in str1:
count+=1
return count
def strcopy(src):
dst=[]
for i in src:
dst.append(i)
dst=''.join(dst)
return dst
str1='New Delhi'
len1=strlength(str1)
print 'The length of the string is ',len1
str2=strcopy(str1)
print 'First string is %s and copied string is %s' %(str1,str2)
def strcompare(str1,str2):
len1=len(str1)
len2=len(str2)
if len1<len2:
length=len1
else:
length=len2
for i in xrange(0,length):
if str1[i]<str2[i]:
return -1
elif str1[i]>str2[i]:
return 1
return 0
str1='Programming'
str2='Computer'
status=strcompare(str1,str2)
if status==-1:
print 'First string is lesser than second string'
elif status==1:
print 'First string is greater than second string'
else:
print 'Both strings ae equal'
def leftconcat(dst,src):
dst=src+dst
return dst
def rightconcat(dst,src):
dst=dst+src
return dst
str1='Hello'
str2='Friends'
tempstr=leftconcat(str2,str1)
print 'The first string after left concatenation becomes ', tempstr
tempstr=rightconcat(str2,str1)
print 'The first string after right concatenation becomes', tempstr
str1='All good boys have bread'
count=0
for i in str1:
if i=='a' or i=='e'or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U' :
count+=1
print 'Total number of vowels in a given text are ',count
ch1='A'
ch2=ord(ch1)+3
print chr(ch2)
ch1=chr(ord(ch1)+1)
print ch1
print ord('a')
print ord('l')
val=ord(ch1)*ch2
print val
print chr(100)
text='I am studying 6 Theory Papers & 4 practicals'
len1=len(text)
text=list(text)
for i in xrange(0,len1):
if text[i]>='a' and text[i]<='z':
text[i]=chr(ord(text[i])+ord('A')-ord('a'))
text=''.join(text)
print 'The text after converting lowercase alphabets to uppercase is '
print text
text='The programming is a systematic process'
substr='pro'
text_len=len(text)
sub_len=len(substr)
text=list(text)
substr=list(substr)
for i in xrange(0,text_len-sub_len+1):
for j in xrange(0,sub_len):
if text[i+j]==substr[j]:
continue
else:
break
if j==sub_len-1:
print 'The substring is present from subscript %d onwards' %i
def reorder(x):
n=len(x)
for item in range(0,n-1):
for i in range(item+1,n):
if x[item]>x[i]:
temp=x[item]
x[item]=x[i]
x[i]=temp
return
x=['PACIFIC','ATLANTIC','INDIAN','CARIBBEAN','BERING','BLACK','RED','NORTH','BALTIC','CASPIAN']
print 'Original list of strings :\n\n'
for i in x:
print "String : ",i
reorder(x)
print "\nReodered list of strings : \n\n"
for i in x:
print "String : ",i