Computer Science
What will be the output produced by following code fragments?
x = "hello" + \
"to Python" + \
"world"
for char in x :
y = char
print (y, ' : ', end = ' ')
Python
Python String Manipulation
30 Likes
Answer
h : e : l : l : o : t : o : : P : y : t : h : o : n : w : o : r : l : d :
Working
Inside the for loop, we are traversing the string "helloto Pythonworld" character by character and printing each character followed by a colon (:).
Answered By
17 Likes
Related Questions
What is the result of the following expression?
s ='987654321' print (s[-1], s[-3]) print (s[-3:], s[:-3]) print (s[-100:-3], s[-100:3])
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)
What will be the output produced by following code fragments?
x = "hello world" print (x[:2], x[:-2], x[-2:]) print (x[6], x[2:4]) print (x[2:-3], x[-4:-2])
Carefully go through the code given below and answer the questions based on it :
theStr = " This is a test " inputStr = input(" Enter integer: ") inputlnt = int(inputStr) testStr = theStr while inputlnt >= 0 : testStr = testStr[1:-1] inputlnt = inputlnt - 1 testBool = 't' in testStr print (theStr) # Line 1 print (testStr) # Line 2 print (inputlnt) # Line 3 print (testBool) # Line 4
Given the input integer 3, what output is produced by Line 1?
- This is a test
- This is a
- is a test
- is a
- None of these