Logic Building
# Take string input
s = input("Enter a string: ")
# Print last character
if len(s) > 0:
print(f"Last character: {s[-1]}")
else:
print("String is empty")Output
Enter a string: Hello Last character: o
Access last character using index -1.
Key Concepts:
- s[-1] is last character
- Negative indexing
- Check if string not empty