Computer Science
Which line of code produces an error ?
- "one" + 'two'
- 1 + 2
- "one" + "2"
- '1' + 2
Python String Manipulation
1 Like
Answer
'1' + 2
Reason — The + operator has to have both operands of the same type either of number type (for addition) or of string type (for concatenation). It cannot work with one operand as string and one as a number.
Answered By
3 Likes
Related Questions
You have the following code segment :
String1 = "my" String2 = "work" print(String1 + String2)
What is the output of this code?
- my work
- work
- mywork
- my
You have the following code segment :
String1 = "my" String2 = "work" print(String1+String2.upper())
What is the output of this code?
- mywork
- MY Work
- myWORK
- My Work
What is the output of this code ?
>>> int("3" + "4")
- "7"
- "34"
- 34
- 24
Which line of code will cause an error ?
1. num= [5, 4, 3, [2], 1] 2. print(num[0]) 3. print(num[3][0]) 4. print(num[5])
- Line 3
- Line 2
- Line 4
- Line 1