CBSE Class 11 Computer Science Question 61 of 91

String Manipulation — Question 6

Back to all questions
6
Question

Question 2a

What will be the output produced by following code fragments?

y = str(123)
x = "hello" * 3
print (x, y)
x = "hello" + "world"
y = len(x)
print (y, x)

Answer

Output
hellohellohello 123
10 helloworld
Explanation

str(123) converts the number 123 to string and stores in y so y becomes "123". "hello" * 3 repeats "hello" 3 times and stores it in x so x becomes "hellohellohello".

"hello" + "world" concatenates both the strings so x becomes "helloworld". As "helloworld" contains 10 characters so len(x) returns 10.

Answer