+ is used to concatenate and * is used to multiply strings.
Understanding Arithmetic Operators with Strings:
1. * (Multiplication):
• Strings can be multiplied with integers to create repeated copies of the string.
• Example:
print(“abc” * 3) # Output: abcabcabc
• Allowed with strings.
2. – (Subtraction):
• Subtraction is not defined for strings in Python. You cannot subtract one string from another.
• Example:
print(“abc” – “a”) # This will raise a TypeError.
• Not allowed with strings.
3. + (Addition):
• Strings can be concatenated (joined) using the + operator.
• Example:
print(“abc” + “def”) # Output: abcdef
• Allowed with strings.
4. All of the mentioned:
• Since both * and + are allowed with strings, not all arithmetic operators are disallowed. Only – (subtraction) cannot be used with strings.
Correct Answer:
b) –
Subtraction (-) is the arithmetic operator that cannot be used with strings in Python.
+ is used to concatenate and * is used to multiply strings.
Understanding Arithmetic Operators with Strings:
1. * (Multiplication):
• Strings can be multiplied with integers to create repeated copies of the string.
• Example:
print(“abc” * 3) # Output: abcabcabc
• Allowed with strings.
2. – (Subtraction):
• Subtraction is not defined for strings in Python. You cannot subtract one string from another.
• Example:
print(“abc” – “a”) # This will raise a TypeError.
• Not allowed with strings.
3. + (Addition):
• Strings can be concatenated (joined) using the + operator.
• Example:
print(“abc” + “def”) # Output: abcdef
• Allowed with strings.
4. All of the mentioned:
• Since both * and + are allowed with strings, not all arithmetic operators are disallowed. Only – (subtraction) cannot be used with strings.
Correct Answer:
b) –
Subtraction (-) is the arithmetic operator that cannot be used with strings in Python.