0

Hey guys,

In Java, there is a method called substring, but what substitute does it have in Python, or do I have to explicitly do it like:

s=raw_input("Enter a sentence: ")
s2=""
a=0
b=0
for a in s:
    if(a==' '):
       s2= s[b:a]
        b=a
    a+=1

Thanks guys!

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by jlm699
0

The equivalent device in python is slicing:

>>> my_text = 'Rajesh Kumar'
>>> my_text[3:]
'esh Kumar'
>>> my_text[1:2]
'a'
>>>

This example is analogous to the example on this page, which gives example usage of Java substring.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.