String methods in python with examples – My Programming School


String methods in python with examples – My Programming School

String methods in python with examples

Strings modules include many useful constants and classes,therefore some deprecated inheritance functions that are also available as strings methods. In addition, Python’s built-in string classes support sequence type methods described in sequence types – str, bytes, bytearray, list, tuple, category section, and string-specific methods also described in the string-specific methods section. To output formatted strings, see the String Formatting section. Also, see the re-module for string functions based on regular expressions.

Aim

To perform  various operation on string using string libraries with algorithm

Implement python  various operation on string using string libraries | algorithm

step1: Start

step2: initialise upper case letters capital = str.upper()

step3: Initialise upper case letter small = capital.lower()

step4: 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 to implement string methods in python

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:

String methods in python with examples

Related Link:

Strings methods in python with examples – My Programming School

Tags

python string format,python string split,python string,python string replace, python string methods,python string find,python string index,python string operations,

Have any Question or Comment?

Leave a Reply

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

Categories