How to Handle String in Python

String in Python
my_string = ‘Hi’
print(my_string)

my_string = “Hi”
print(my_string)

my_string = ”’Hi”’
print(my_string)

# triple quotes string can extend multiple lines
my_string = “””Hello, welcome to Python”””
print(my_string)

Concatenation of String
s1 = ‘Hello’
s2 =’World!’

# using +
print(‘s1 + s2 = ‘, s1 + s2)

# using *
print(‘s1 * 3 =’, s1 * 3)

# Program to check if a string is palindrome or not

# change this value for a different output
my_str = ‘abBA’

# make it suitable for caseless comparison
str = str.casefold()
# reverse the string
rev_str = reversed(str)
if list(str) == list(rev_str):
print(“It is palindrome”)
else:
print(“It is not palindrome”)

Leave a Reply

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