As shown in the official Python tutorial,

>>> word = 'Python'

[...]

Indices may also be negative numbers, to start counting from the right:

>>> word[-1]  # last character
'n'
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-get-last-n-characters-of-a-string
Get Last N characters of a string - Python - GeeksforGeeks
July 23, 2025 - String slicing is the fastest and most straightforward way to get the last N characters from a string. Itโ€™s built into Python and highly optimized for such tasks. ... slicing operation s[-n:] retrieves the substring starting from the Nth position from the end to the end of the string.
Discussions

How do i extract last character from a string
Hi experts, How do I use regex to extract 1 and 2 from the list of documents ie: Document ABC v1 Document ABC v2 I have to use the numbers to do comparison thanks. More on forum.uipath.com
๐ŸŒ forum.uipath.com
9
0
March 7, 2024
How to replace the last (and only last) character in a string? - Post.Byes
Re: How to replace the last (and only last) character in a string? More on post.bytes.com
๐ŸŒ post.bytes.com
May 3, 2007
how to get what index position the last character of a string is
this could have been solved with 5 minutes of experimentation if you're going to be a programmer you have to start experimenting with code, just test and try stuff out More on reddit.com
๐ŸŒ r/learnpython
13
3
April 2, 2022
5 Ways You Can Remove Last Character From String in Python
Method 1 and 2 are the same, except that defining a variable that doesn't do anything but hold the length of string 1 is even a bit more inefficient than method 1. Importing the re module to remove a character from a string is just ridiculous. Also it's not removing the last character, but deleting all 'n's. Could have achieved the same with the built-in str.replace() method. str.rstrip() isn't used correctly. It won't remove the last character, but will also shorten 'helloooooo' to 'hell'. The loop also removes all 'n's, not necessarily the last character. Plus it is highly inefficient and not pythonic in any way More on reddit.com
๐ŸŒ r/programming
3
0
July 19, 2021
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to get what index position the last character of a string is
r/learnpython on Reddit: how to get what index position the last character of a string is
April 2, 2022 -

Hey. I'm trying to get the index position of the last character in a string. For example, if the string is "Hello" , I want the program to only print that the last character (in this case 'o') is in index position 4. The string would be inputted by the user though so its always going to be different.

I'm familiar with (len(string)) and string[-1] but not sure how to use them together, if I even need to.

๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ last-character-string-python
Get the Last Character of a String in Python - Flexiple
Python provides convenient string methods that simplify tasks like getting the last character. One such method is str[-1], which directly returns the last character of the string. Another approach is using str[-1:], which also gives the last ...
๐ŸŒ
Stanford CS
cs.stanford.edu โ€บ people โ€บ nick โ€บ py โ€บ python-string.html
Python Strings
Python strings are written between ... pretty much every language on earth, plus many emojis. See the unicode section below for more information. The len() function returns the length of ......
๐ŸŒ
Jeremy Morgan
jeremymorgan.com โ€บ python โ€บ how-to-get-the-last-character-of-a-string-python
How to Get the Last Character of a String in Python
The most common method is by using slicing, which allows you to extract a portion of a string based on a start and end index. In this article, we will explore how to use slicing to get the last character of a string. The basic syntax for slicing in Python is string[start:end]....
Find elsewhere
๐ŸŒ
Replit
replit.com โ€บ home โ€บ discover โ€บ how to get the last character of a string in python
How to get the last character of a string in Python | Replit
April 14, 2026 - Learn how to get the last character of a string in Python. Explore various methods, tips, real-world uses, and common error debugging.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_strings.asp
Python Strings
Since strings are arrays, we can loop through the characters in a string, with a for loop. ... Learn more about For Loops in our Python For Loops chapter. To get the length of a string, use the len() function.
๐ŸŒ
Quora
quora.com โ€บ How-can-I-get-last-four-characters-of-a-string-in-python
How to get last four characters of a string in python - Quora
Answer (1 of 6): str = "Hello How are you?" print(str[len(str)-4:]) String can be treated as an array. So we can access each char with indexing. To get last four elements simply calculate itโ€™s length using โ€œlen(str)โ€ (itโ€™s an inbuilt function in python) then on subtracting 4 from it ...
๐ŸŒ
RS Blog
reneshbedre.com โ€บ blog โ€บ last-characters-string.html
3 ways to get the last characters of a string in Python
August 17, 2021 - The numeric string index in Python is zero-based i.e., the first character of the string starts with 0. If you know the length of the string, you can easily get the last character of the string
๐ŸŒ
UiPath Community
forum.uipath.com โ€บ help โ€บ studio
How do i extract last character from a string - Studio - UiPath Community Forum
March 7, 2024 - Hi experts, How do I use regex to extract 1 and 2 from the list of documents ie: Document ABC v1 Document ABC v2 I have to use the numbers to do comparison thanks.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-can-i-get-last-4-characters-of-a-string-in-python
How can I get last 4 characters of a string in Python?
March 15, 2026 - Use string[-4:] to get the last 4 characters efficiently. This method handles short strings gracefully and is the most Pythonic approach for extracting characters from the end of a string.
๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ home โ€บ technologies โ€บ python โ€บ how to get the last n characters of a string in python
How To Get The Last N Characters Of A String In Python
July 27, 2023 - In this method, we will first find the length of the string and then we will print the last N characters of the string.
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ python-replace-last-character-in-string
Replace the Last or Last N characters in a String in Python | bobbyhadz
April 9, 2024 - The slice my_str[:-1] starts at index 0 and goes up to, but not including the last character of the string. ... The syntax for string slicing is my_str[start:stop:step]. The start index is inclusive, whereas the stop index is exclusive (up to, but not including). Python indexes are zero-based, ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-to-get-the-last-n-characters-of-a-string-in-python
How to Get the Last N characters of a String in Python
July 18, 2023 - def get_last_n_characters(text, n): slice_obj = slice(-n, None) return text[slice_obj] text = "Hello, world!" n = 5 result = get_last_n_characters(text, n) print(f"Last {n} characters: {result}") # Reusing the slice object last_3 = slice(-3, None) print("Python"[last_3]) # hon print("Programming"[last_3]) # ing ... The deque with maxlen parameter automatically maintains only the last N elements, making it memory-efficient for large strings.
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 371-how-do-i-get-last-character-string.html
How do I get the last character of a string?
August 26, 2001 - strlen() returns the length of a string not counting the null byte so :- startaddressofstring+strlen(string)-1 will give you the address of the last character.From there all you need do is dereference that pointer and place a new value in there. Free the weed!!
๐ŸŒ
Post.Byes
post.bytes.com โ€บ home โ€บ forum โ€บ topic โ€บ python โ€บ how to replace the last (and only last) character in a string?
How to replace the last (and only last) character in a string? - Post.Byes
May 3, 2007 - [/docstring] Notice the "all occurrences of substring" part. Strings are immutable, so there isn't really any replace, either way you are going to be creating a new string. So the best way to do what (I think) you want to do is this... ... [QUOTE][QUOTE][QUOTE] >>s = '12345 4343 454' >>s = s[:-1]+'r' >>s[/QUOTE][/QUOTE][/QUOTE] '12345 4343 45r' ... Re: How to replace the last (and only last) character in a string? On 2007-05-03, Johny <python@hope.cz wrote:
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ re.html
re โ€” Regular expression operations
A brief explanation of the format of regular expressions follows. For further information and a gentler presentation, consult the Regular expression HOWTO. Regular expressions can contain both special and ordinary characters. Most ordinary characters, like 'A', 'a', or '0', are the simplest regular expressions; they simply match themselves. You can concatenate ordinary characters, so last matches the string ...
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-get-the-characters-in-a-string-in-python
How to get the character(s) in a string in Python
... In the example below, you can use the same syntax to extract a few characters instead of just one. ... When you use the syntax print(Name[0:]), Python will assume the indexes from zero to the last index by ...
๐ŸŒ
Quora
quora.com โ€บ How-do-I-get-the-last-word-of-a-string-in-Python
How to get the last word of a string in Python - Quora
Answer: Assuming words are separated by whitespace, you could get the last word from a given string as follows: [code]s = 'This is a sample string' last_word = s.split()[-1] [/code]This is how it works: s.split() returns a list consisting all the words by splitting the string, assuming words are...