Computer Science
Write the output of the following:
>>> x = "hello"
>>> print(x[1:-2])
Python
Python String Manipulation
2 Likes
Answer
el
Working
The statement x[1:-2] slices the string "hello" starting from index 1 up to index -3. This results in the substring "el", so print(x[1:-2]) outputs "el".
Answered By
1 Like
Related Questions
Explain function split() with an example.
How many times is the word 'HELLO' printed in the following statement?
s = "python rocks" for ch in s: print ("Hello")Write the output of the following:
string = "Hello Madam, I love Tutorials" substring = "Madam" if string.find(substring) != -1: print("Python found the substring!") else: print("Python did NOT find the substring!")Write the output of the following:
s = "Strings in Python" print(s.capitalize()) print(s.title()) s6 = s.replace("in", "data type") print(s6)