Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

What is a string slice ? How is it useful ?

Answer» A sub-part or a slice of a string, say s, can be obtained using s[n : m] where n and m are integers. Python returns all the characters at indices n, n+1, n+2,…. m-1. For example,

‘Oswaal Books’ [1 : 4] will give ‘swa’
52.

How you can “update” an existing string ?

Answer» You can “update” an existing string by (re) assigning a variable to another string

The new value can be related to its previous value or to a completely different string altogether.

Following is a simple example :

# !/usr/bin/python

var1 = ‘Hello World!’

print”Updated String:-“,var i[:6] + ‘Python’