27-Feb-2023
.
Admin
Hi Dev,
This article will give you example of get last word from string in python example. you will learn python last word of. I explained simply step by step how to get last word in. I explained simply step by step how to get last word from string in pythonpythonstring.
In this example, i will add myString variable with hello string. Then we will use split() function to getting 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 nicesnippets.com"
# Getting Last Word from String
firstWord = myString.split()[-1]
print(firstWord)
Output:
nicesnippets.com
#Python