Computer Science
What will be the output of the following programming code?
str = "My Python Programming"
print (str[-5:-1])
print (str[1:5])
print (str[:-4])
print (str[0:])
print (str[:13-4])
print (str[:3])
Python
Python String Manipulation
3 Likes
Answer
mmin
y Py
My Python Program
My Python Programming
My Python
My
Working
str[-5:-1]extracts the substring from the 5th last character up to, but not including, the last character: "mmin".str[1:5]extracts the substring from index 1 to 4: "y Py".str[:-4]extracts the substring from the beginning up to, but not including, the last 4 characters.str[0:]extracts the substring from index 0 to the end.str[:13-4]is equivalent to str[:9], which extracts the substring from the beginning up to, but not including, index 9: "My Python".str[:3]extracts the substring from the beginning up to, but not including, index 3: "My ".
Answered By
1 Like
Related Questions
Write a program that takes a sentence as an input parameter where each word in the sentence is separated by a space. The function should replace each blank with a hyphen and then return the modified sentence.
Write a script to partition the string 'INSTITUTE' at the occurrence of letter 'T'.
Write a program to count the number of each vowel in a given string.
Write a program that reads a line, then counts how many times the word 'is' appears in the line and displays the count.