KnowledgeBoat Logo

Computer Science

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)

Python

Python String Manipulation

37 Likes

Answer

hellohellohello 123
10 helloworld

Working

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.

Answered By

13 Likes


Related Questions