close

How to extract Substring From a String in Python

Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about how to extract Substring From a String in Python. so without wasting time lets learn about of this.

How to extract Substring From a String in Python

  1. extract Substring From a String in Python

    to extract Substring From a String in Python just use this method. By this method you can remove the item which you wanting to remove . Lets learn this by below example: string = "Exerror.com" print(string[0:7]) Output : Exerror

  2. How to extract Substring From a String in Python

    to extract Substring From a String in Python just use this method. By this method you can remove the item which you wanting to remove . Lets learn this by below example: string = "Exerror.com" print(string[0:7]) print(string[2:7]) print(string[8:11]) Output : Exerror error com

Method 1

By this method you can extract Substring From a String. Lets learn this by below example:

string = "Exerror.com"
print(string[0:7])

Output :

Exerror

Method 2

By this method you can extract Substring In This way. Lets learn this by below example:

string = "Exerror.com"
print(string[0:7])
print(string[2:7])
print(string[8:11])

Output :

Exerror
error
com

Method 3

By this method you can extract Substring. Lets learn this by below example:

string = "Exerror.com"
print(string.rpartition('.')[0])
print(string.rpartition('.')[2])

Output :

Exerror
com

Conclusion

It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?

Also, Read

Leave a Comment