Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions string slicing and indexing task .py
Original file line number Diff line number Diff line change
@@ -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))