Computer Science
Which arithmetic operator(s) cannot be used with strings ?
- +
- *
- -
- All of these
Answer
-
Reason — The arithmetic operator "-" (minus) cannot be used with strings in Python. The "+" operator is used for string concatenation, "*" is used for string repetition, but the "-" (minus) operator does not have a defined meaning for strings and will result in an error if used with strings.
Related Questions
What is the output of the following ?
d = {0: 'a', 1: 'b', 2: 'c'} for i in d: print(i)
1.
0 1 2
2.
a b c
3.
0 a 1 b 2 c
4.
2 a 2 b 2 c
What is the output of the following ?
x = 123 for i in x: print(i)
- 1 2 3
- 123
- Error
- Infinite loop
What will be the output when the following code is executed?
>>> strl = "helloworld" >>> strl[ : : -1]
- dlrowolleh
- hello
- world
- helloworld
What is the output of the following statement?
python print("xyyzxyzxzxyy".count('yy', 1))
- 2
- 0
- 1
- Error