0% found this document useful (0 votes)
4 views1 page

String Manipulation Techniques in Python

Uploaded by

monishatolen
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

String Manipulation Techniques in Python

Uploaded by

monishatolen
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Get two strings through a single line

str1,str2=map(str, input("Enter the two strings separated by a str1,str2=map(str,


space = ").split(" ")) input("Enter the two
print("String-1 = ",str1,"\nString-2 = ",str2) strings separated by a
space = ").split(" "))
print("String-1 =
",str1,"\nString-2 =
",str2)
2. Reverse a string

str1="Orange" The reversed string =


print("The reversed string = ",''.join(reversed(str1))) egnarO
str1="Orange"
print("The reversed string = ",str1[::-1])
str1="Orange"
rev = ""
for ch in str1:
rev = ch + rev
print("The reversed string = ",rev)
str1="Orange"
rev = ""
rev = ''.join([str1[i] for i in range(len(str1) - 1, -1, -1)])
print("The reversed string = ",rev)
3. Concatenate str2 with str1

4.

5.

You might also like