String Operation:
Python provides many built-in string operations that you can use to manipulate strings. Here are some common string operations in Python:
Example:
str1 = "Hello"
str2 = "world"
result = str1 + " " + str2
print(result)
Output:
Hello world
Example:
str1 = "Hello world"
substring = str1[6:11]
print(substring)
Output:
world
Example:
str1 = "Hello world"
new_str = str1.replace("world", "Python")
print(new_str)
Output:
Hello Python
Example:
str1 = "Hello,world"
split_str = str1.split(",")
print(split_str)
Output:
['Hello', 'world']
Example:
name = "John"
age = 25
formatted_str = "My name is {} and I am {} years old".format(name, age)
print(formatted_str)
Output:
My name is John and I am 25 years old
Learners TV is a website that is designed to educate users and provide instructional material on particular subjects and topics.