Write a Python Program to Get a Substring of a String

Python Program to Get a Substring of a String

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn  Python programming concepts. You can learn Python language at your own speed and time. One can learn concepts of Python language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Python Program to Get a Substring of a String
Python Program to Get a Substring of a String

Write a Python Program to Get a Substring of a String

PROGRAM: Python Program to Get a Substring of a String

/* Python Program to Get a Substring of a String */

Using String slicing

my_string = “I love python.”

# prints “love”
print(my_string[2:6])

# prints “love python.”
print(my_string[2:])

# prints “I love python”
print(my_string[:-1])

OUTPUT:-

love
love python.
I love python

Leave a Reply

Your email address will not be published. Required fields are marked *