I am not able to understand and solve the question

Print Substring!

Problem Description

Given a string A and two integer B and C.

Find and return the substring of A starting from index B and ending with index C.


  • Consider 0 based indexing.
  • Try to use direct library function to solve this.

Problem Constraints

1 <= |A| <= 100

0 <= B, C < |A|

Input Format

First argument is an string A.

Second argument is an integer B.

Third argument is an integer C.

Output Format

Return the substring of A starting from index B and ending with index C.

Example Input

Input 1:

A = “rishabh” B = 1 C = 2

Input 2:

A = “ojas” B = 0 C = 0

Example Output

Output 1:


Output 2:


Example Explanation

Explanation 1:

Substring from index 1 to index 2 in “rishabh” is “is”.

Guys I am a new learned and I am from non technical background, but I need to switch in IT (Information Technology), its just been 2 days now I started learning python from scaler, and got this kind of question which is going above my mind so its a humble request that plz do help me to grow and learn this python language.

Possibly, a good place to start, would be to consider what you do know, rather than what you don’t know.

For example, do you know what these expressions mean?

  1. =
  2. >
  3. <
  4. >=
  5. <=

The math equivalent of (4) and (5) is:

So, (1) should be simple; its the equality or ‘equal to’ symbol. There is a caveat here and it’s something that you’re going to fall over if you’re not paying attention: in Python, if you see x = 1 that’s an ‘assignment’, that is to say that x has been assigned the value of 1, whereas x == 1 is a ‘comparison’, that is to say, we asking ‘if x is equal to 1’. It’s a very important point and one you need to understand.

Given what we have already, I’m not going say anything more until you reply (you’d maybe be surprised at how many times I’ve tried to help a new user, just to have them never come back), but you’ll need to understand what those expressions mean in order to understand the Problem Constraints, the Example Inputs and some basic Python code.

I really appreciate for your reply, and yes I do know and understand the expressions, but I would like to tell you that I do not have any programming or computer background in my Graduation, so I am not so familiar with languages, but in high school I did had the computer as subject back then in 2013, so I do have an idea about it. I need help to understand the question and to solve it until then I will not proceed the course until I get an answer to the problem which I want to solve but for solving the question i need help that is the reason I am trying to get the help.

Okay. Let me see if I can help you with the concept of ‘zero indexing’. Indexing is another fundamental concept that is key to Python coding and, by default, an index starts at zero, not one.

Consider this string of characters: python

The index for that string is thus:

0 | 1 | 2 | 3 | 4 | 5
p | y | t | h | o | n

So, if we have this simple code:

name = 'python'

… we will see the letter y displayed. If we wanted the first three letter, we’d use print(name[0:3]) and we’d see pyt displayed. Notice here that the forth letter is h and is at index position 3. So, that pyt ‘sub-string’ is three characters in length and is a so-called ‘slice’ of the name object to which the string python has been assigned and is constructed from index position 0 up to, but not including, index position 3.

What we could now do, is to assign our python string to object A and two integer values to two more objects (B and C) and use those, like this:

A = 'python'
B = 0
C = 3


… which would display the same sub-string: pyt

This satisfies the Problem Constraints, namely that our ‘string’, (which is represented as |A|) is greater than or equal to 1 character and is less than or equal to 100 characters, B is greater than or equal to 0 and C less than the length of the ‘string’. If you wanted your code to display the length of your ‘string’, you can use a builtin function called len().

You can see that it’s a function, because of the parentheses, and you can combine functions like this: print(len(A)). Here, the len() function will return the length of the string of characters that have been assigned to the A object, and pass that value to the print() function, which will in turn display said value.

So, given this information, you should now be able to apply what you’ve learned to the task at hand.

If you look a bit more closely at the examples given, you’ll see that it’s not exactly like Python. Python uses half-open ranges (excludes the end position) whereas the examples use closed ranges (includes the end position).

Thank you so much for your reply I really appreciate that you have given me the answer and how I can try the concept which you have mentioned.

But I would like to request you one thing is it possible for you to solve the answer and send it to me in explained manner one more time so that I can try right down to save solution which you have given to me I’ll bet you will give it to me later on and I can practise the same thing to understand and practise at the same time.

Thank you so much for your valuable reply and attention to my question which I have asked on this community I would like an answer that how I can solve it if you can copy paste your answer that how I can solve the question which I have already mentioned about will be a great help appreciated so that I can learn and practise at the same time and accordingly I can continue my Python course after solving this challenge but I need the answer so that I can understand it my Moto is to clear all my concepts unrelated to Python as I recently started it.

Have go, write some code and post back if you get stuck. I’ve given you all you need to enable you to do this for yourself.

Rob has already given you enough to solve the problem. I just pointed out that, for Python, you’ll need to add 1 to the end position.

Thank you so much for your reply and yes I just figured it out that you have already given the answer to my question and now I’m really able to solve the question which was a challenge for me right now. It is all your help and support that I was able to solve it thank you so much for your help and support I thought that i will not get enough support in community but unfortunately I was wrong and I do got a lot of help from which is really very valuable for me in my current path. Thank you so much from bottom of my heart to you.

1 Like

Thank you so much for your valuable time and advice Matthew it was really helpful for me and thank you so much for pointing out the necessary points which was already mentioned by rob.

You are more than welcome and I’m please to have been able to restore some faith in our community as well as being able to have given you a better understanding.

1 Like