ItSolutionStuff.com

How to Remove Last Word from String in Python?

By Hardik Savani • October 30, 2023
Python

Hello Artisan,

This post is focused on python get last word from string. I would like to share with you python get last word in string. I am going to show you about how to get last word in string python. We will look at an example of how to get last word from string in python. Follow the below tutorial step of how to get last word in python.

In this example, i will add myString variable with hello string. Then we will use rsplit() function to delete last word from string in python. So, without further ado, let's see simple examples: You can use these examples with python3 (Python 3) version.

Example:

main.py

# Declare String Variable
myString = "Hello This is ItSolutionStuff.com"
  
# Delete Last Word from String
newString = myString.rsplit(' ', 1)[0]
  
print(firstWord)

Output:

Hello, This is

I hope it can help you...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get Last Word from String in Python?

Read Now →

How to Get First Word from String in Python?

Read Now →

Python PNG Image to Base64 String Example

Read Now →

Python Pandas Read Excel File Multiple Sheets Example

Read Now →

Python Read CSV File Specific Column Example

Read Now →

How to Capitalize String in Python?

Read Now →

Python String Convert to Lowercase Example

Read Now →

Python String Convert to Uppercase Example

Read Now →

Python Convert List into String with Commas Example

Read Now →

How to Convert List into String in Python?

Read Now →

Python Split String into List of Characters Example

Read Now →

How to Convert String into List in Python?

Read Now →

Python Remove Empty String from List Example

Read Now →