tring methods in python with examples


Q) : Implement python  various operation on string using string libraries with algorithm

Aim : To perform  various operation on string using string libraries with algorithm

Algorithm :

step 1: Start
step 2: initialise upper case letters
          capotal = str.upper()
step 3: Initialise upper case letter 
           small = capital.lower()
step 4: Replace str1 to str2
         str2 = str1.replace(“students’,”engineer”)
step 5: print left and right strips
          left  = str1.strip()
          right = str1.strip()
step 6: print prefixes
          prefix1 = str1.startwith(“wel come”)
step 7: end

Source Code:

str1 = "welcome to all student"
capital = str1.upper()
print(capital)
str2 = "WELCOME TO MITS"lower = str2.lower()
print(str2)
str3 = str2.replace("MITS","madanapalle")
print(str3)
str4 = "This is an example of strip"left = str4.strip()
print(left)
prefix1 = str1.startswith('hellow')
print(prefix1)
prefix2 = str1.startswith('wel')
print(prefix2)
prefix3 = str1.endswith('student')
print(prefix3)


Output:
 
WELCOME TO ALL STUDENT
welcome to mits
WELCOME TO madanapalle
This is an example of strip
False
True
True

Process finished with exit code 0



Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

Domain & free Hosting

Categories

You have successfully subscribed to myprogrammingschool

There was an error while trying to send your request. Please try again.

My Programming School will use the information you provide on this form to be in touch with you and to provide updates and marketing.