Python: Get last 4 characters of a string [one line code]

Python code to get last four characters of a string.

This single line code, excluding string line, prints the last 4 characters of the string. Change the number to get more or less characters.

Example string: GetHowStuff

Expected Output (last 4 characters): tuff

string="GetHowStuff"
#prints last 4 characters of the string
print(string[-4:])

About the Author

SRINI S

A passionate blogger. Love to share solutions and best practices on wordpress hosting, issues and fixes, excel VBA macros and other apps

Leave a Reply

Your email address will not be published.