Strings And String Processing in Python

If you are learning a new programming language, usually string manipulation exercise are among the first thing to do. Python has a wide library of functions for string manipulation. Please watch my video below for the presentation








Here are the code that I have used for the demo:

print ("Hello World")
## this is a comment
# String Variables

str1="This is a string"
print (str1)
#string is a zero based array of characters
print(str1[0])
print(str1[1])
print(str1[3])

#print ("****the first six charachter*****")
print (str1[0:5])

#print ("****the 2nd to 8th*****")
print (str1[1:7])
#print ("****6th characters and onward *****")
print (str1[5:])

str4='"this a string created with single qoute"'
print(str4)

str5="this's a string created with double qoute"
print(str5)

str5='this\'s a string created with single qoute and escape charater'
print(str5)

#long strig using three single quotes
str6=''' this is a lOnG...
long... span manyline
string'''
print(str6)

#long strig using three double quotes
str7="""this is a lOnG...
long... span manyline
string ex2"""
print(str7)

print (str7.count("s"))
print (str7.find("s"))

print (len(str7))

print (str7.upper())
print("*")
print (str7.lower())
print("*")
print(str7.capitalize())
print("*")
print (str7.title())

str2 = "thisisyear 2009"
print (str2.isalnum())
print (str2.isupper())
print(str2.istitle())
print(str2.isnumeric())

str3 = "non alphanumeric";
print (str3.isalnum())

#concatenation
print("*** string concatenation demo***")
A="I have two hands."
B="the left and the right"
print(A+B)

#repr() Return a string containing a printable representation of an object.

print("****repr demo****")
x=6.0
print (repr(x))
X=7

print ("The value of small x="+repr(x))
print ("The value of X="+repr(X))




Leave a Reply

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