From f40cc5c38f26b9ef74f7d20b6659a51da1191a27 Mon Sep 17 00:00:00 2001 From: Madhumitha Date: Thu, 30 Oct 2025 20:46:19 +0530 Subject: [PATCH] Add example for string slicing and indexing --- String Slicing and Indexing | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 String Slicing and Indexing diff --git a/String Slicing and Indexing b/String Slicing and Indexing new file mode 100644 index 00000000..6a08b9f2 --- /dev/null +++ b/String Slicing and Indexing @@ -0,0 +1,20 @@ +# String Slicing and Indexing Example + +# Input a string from the user +text = input("Enter a string: ") + +# Displaying first and last character +print("First character:", text[0]) +print("Last character:", text[-1]) + +# Display a substring (from index 2 to 5) +print("Substring (index 2 to 5):", text[2:6]) + +# Reverse the string +print("Reversed string:", text[::-1]) + +# Print every second character +print("Every 2nd character:", text[::2]) + +# Length of the string +print("Length of the string:", len(text))