Python Programming - Console Input/Output - Discussion

Discussion Forum : Console Input/Output - General Questions (Q.No. 42)
42.
How can you print the first and last characters of a string?
print("First:", string[0], "Last:", string[-1])
print("First:", string.first(), "Last:", string.last())
print(f"First: {string[0]}, Last: {string[-1]}")
print("First:", first_char(string), "Last:", last_char(string))
Answer: Option
Explanation:
To print the first and last characters of a string, use indexing with string[0] and string[-1].
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.