Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

String Concept in Python:-


The string is a collection of char, it will arrange multiple char using sequence.
The string char index will be to start from 0 to length-1.
The 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 the 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 a 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 the string from the 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 separate string in any String?






7 Comments

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

  1. Assignment1
    #wap to replace string to next consecutive string
    str=input("enter string")
    for i in range (0,len(str)):

    x=ord(str[i])
    if x>=65 and x<=90:
    x=x+1
    print(chr(x))
    else:
    x>=97 and x<=122
    x=x+1
    print(chr(x))

    ReplyDelete
  2. Assignment2
    #wap to convert a string from upper case to lower case and vice-versa
    string=input("enter string")
    for i in range(0,len(string)):
    s=ord(string[i])
    if s>=65 and s<=90:
    s=s+32
    s1=chr(s)
    print(s1,end='')

    else:

    s=s-32
    s1=chr(s)
    print(s1,end='')

    ReplyDelete
  3. Assignment 3-
    #WAP to extract numeric, alphabets, and special char in separate string in any String?
    str=input("enter any string")
    s1=''
    s2=''
    s3=''
    for i in range(0,len(str)):
    s=ord(str[i])
    if s>=48 and s<=57:
    s1=chr(s)
    print("enter string is numeric",s)
    elif(s>=65 and s<=90) or (s>=97 and s<=122):
    s2=chr(s)
    print("alphabet string",s)
    elif(s>=32 and s<=47) or (s>=58 and s<=64) or (s>=123 and s<=126):
    s3=chr(s)
    print("special charcter is",s3)

    ReplyDelete
  4. #predefine method of string
    1)capatlize()-Converts the first character to upper case
    implement-
    s1 = "hello, and hi"

    x = s1.capitalize()

    print (x)
    2)casefold()-Converts string into lower case
    implement-
    s2 = " Welcome To My World"

    x = s2.casefold()

    print(x)
    3)centre()-Returns a centered string
    implement-
    s3 = "banana"

    x = s3.center(20)

    print(x)
    4)count()-Returns the number of times a specified value occurs in a string
    implement-
    s4 = "I love mango,mango is yellow color "

    x = s4.count("mango")

    print(x)
    5)Upper()-Converts a string into upper case
    implement-
    s5 = "Hello my friends"

    x = s5.upper()

    print(x)
    6) translate()- method returns a string where some specified characters are replaced with the character described in a dictionary
    mydict = {65: 70};
    s6 = "Hello hi!";
    print(s6.translate(mydict));

    7)strip()-The strip() method removes any leading (spaces at the beginning) and trailing (spaces at the end) characters (space is the default leading character to remove)

    implement-
    s7 = " company "

    x = s7.strip()

    print("mnc", x, "TCS")
    8)isnumeric()- isnumeric() method returns True if all the characters are numeric (0-9), otherwise False.
    implement-
    s8 = "12345"

    x = s8.isnumeric()

    print(x)
    9) format()- method formats the specified value(s) and insert them inside the string's placeholder.
    example-
    Insert the price inside the placeholder, the price should be in fixed point, two-decimal format:

    implement-

    s9 = "For only {price:.2f} dollars!"
    print(s9.format(price = 49))
    10) islower()- method returns True if all the characters are in lower case, otherwise False.

    Numbers, symbols and spaces are not checked, only alphabet characters.
    Check if all the characters in the text are in lower case:

    s10 = "hello world!"

    x = s10.islower()

    print(x)







































    #predefine method of string
    1)capatlize()-Converts the first character to upper case
    implement-
    s1 = "hello, and hi"

    x = s1.capitalize()

    print (x)
    2)casefold()-Converts string into lower case
    implement-
    s2 = " Welcome To My World"

    x = s2.casefold()

    print(x)
    3)centre()-Returns a centered string
    implement-
    s3 = "banana"

    x = s3.center(20)

    print(x)
    4)count()-Returns the number of times a specified value occurs in a string
    implement-
    s4 = "I love mango,mango is yellow color "

    x = s4.count("mango")

    print(x)
    5)Upper()-Converts a string into upper case
    implement-
    s5 = "Hello my friends"

    x = s5.upper()

    print(x)
    6) translate()- method returns a string where some specified characters are replaced with the character described in a dictionary
    mydict = {65: 70};
    s6 = "Hello hi!";
    print(s6.translate(mydict));

    7)strip()-The strip() method removes any leading (spaces at the beginning) and trailing (spaces at the end) characters (space is the default leading character to remove)

    implement-
    s7 = " company "

    x = s7.strip()

    print("mnc", x, "TCS")
    8)isnumeric()- isnumeric() method returns True if all the characters are numeric (0-9), otherwise False.
    implement-
    s8 = "12345"

    x = s8.isnumeric()

    print(x)
    9) format()- method formats the specified value(s) and insert them inside the string's placeholder.
    example-
    Insert the price inside the placeholder, the price should be in fixed point, two-decimal format:

    implement-

    s9 = "For only {price:.2f} dollars!"
    print(s9.format(price = 49))
    10) islower()- method returns True if all the characters are in lower case, otherwise False.

    Numbers, symbols and spaces are not checked, only alphabet characters.
    Check if all the characters in the text are in lower case:

    s10 = "hello world!"

    x = s10.islower()

    print(x)







































    ReplyDelete
  5. Program to count vowels and consonant in a string-->>

    p="shiva concept solution"
    c=0
    v=0
    for i in range(0,len(p)):
    if p[i]=="a" or p[i]=="e" or p[i]=="i" or p[i]=="o" or p[i]=="u":
    v=v+1
    else:
    c=c+1
    print("total consonants=",c,"total vowels=",v)

    ReplyDelete
  6. Program to check palindrome in string-->>

    1st method-->>

    s="nama"
    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("palindrome")
    else:
    print("not a palindrome")


    2nd method-->>
    x = "refer"
    w=""
    for i in x:
    w=i+w
    if (x==w):
    print ("it is a palindrome")
    else:
    print("it is not a palindrome")

    ReplyDelete
  7. Program to convert string from upper case to lower case and lower case to upper case-->>

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

    ReplyDelete

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