Search This Blog

String Concept in Python:-




String is a collection of char ,it will arrange multiple char using sequence .
String char index will to started from 0 to length-1 of String.
String will be declared using ' '," " and """


a= 'welcome'   #single line string
a= "welcome" #single line
a= """welcome in scs """   #multiple line with proper syntax format




WAP to count total vowel and consonant in String?

s= 'welcome'    #['w','e','l','c','o','m','e']
c=0
d=0
for i in range(0,len(s)):
    if s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u':
        c=c+1
    else:
        d=d+1

print("vowel",c,"consonant",d)     


......................................................................
MOST OF THE STRING PROGRAM WILL BE RELATED WITH ASCII CODE HENCE PYTHON PROVIDE TWO DIFFERENT METHOD TO PERFORM OPERATION FROM
ASCII TO CHAR AND CHAR TO ASCII

print(ord('a'))  #97   #char to ascii
print(chr(65))   #A    #ascii to char


WAP to find max char in String?

s= 'ramesh'
m = s[0]
for i in range(1,len(s)):
   if m<s[i]:   #s<h
       m=s[i]
print(m) 


ASSIGNMENT:-
1)WAP to  reverse string where vowel will be in same position?

for example  ramesh          hasemr

Solution:-
s="ramesh"
s1="";
c = 5
for i in range(0,len(s)):
    if s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u':
        s1+=s[i]
    else:
        if s[c-i]=='a' or s[c-i]=='e' or s[c-i]=='i' or s[c-i]=='o' or s[c-i]=='u':
            s1+=s[i]
        else:
            s1=s1+s[c-i]
         

print(s1)   

2) WAP to check palindrome in String?

example  madam,naman

Solution
s="madam"

c = len(s)-1
flag=True
for i in range(0,len(s)//2):
    if s[i]!=s[c-i]:
        flag=False
        break
 
if flag:
    print("pallindrom")
else:
    print("np")
     


3) WAP to convert string from upper case to lower case and lower case to upper case?

Solution:-
s="MADAM"
s1=""

for i in range(0,len(s)):
   s1+=chr(ord(s[i])+32)
print(s1)

4) WAP to replace string from next consecutive String  (if char will be z then replace by a)?

   manish  o.p  nbojti 


5) WAP to extract numeric,alphabets and special char in separet string in any String?







Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post