Robotics & Artificial Intelligence
Answer
The following are some string operators:
1. Replication operator (*) — The replication operator in Python is used to repeat a string for a specified number of times.
Example:
s1 = "Hello"
print(s1 * 4)
Output: HelloHelloHelloHello
2. Concatenation operator (+) — The concatenation operator (+) is used for joining multiple strings.
Example:
print("Hello" + " Hi")
Output: Hello Hi
3. Membership operator (in) — The membership operator returns true if a character exists in the given string.
Example:
if 't' in "Mountain":
print("t is present in mountain")
Output: t is present in mountain
4. Membership operator (not in) — This operator returns true if a character does not exist in the given string.
Example:
if 'k' not in "Mountain":
print("k is not present in mountain")
Output: k is not present in mountain
Related Questions
Write a Python program to create a sub string from a string.
Write a Python program to demonstrate the use of the join function.
Write a Python program to check that a given string contains only alpha numeric characters. If user is not entering alphanumeric characters prompt him or her to enter it again.
Write a Python program for the following task:
Take a string entered by the user and check if it begins with the letter "a" or not. If it begins with "a", the user is prompted that it is the first name on the list. If it does not begin with "a", the user is prompted that the string does not begin with the letter "a".