Course Content
Python Data Types
Python Data Types
Negative Indexing
# Creating a string string = 'codefinity' print("Initial string: ", string) string_1 = string[:-7] print("Elements till 7th element from last: ", string_1) string_2 = string[-7:-4] print("Elements from index -7 to -5:",string_2) string_3 = string[::-1] print("String in reverse order: ", string_3)
Swipe to show code editor
You have such a string programming
.
You have to carry out these steps:
- print elements sliced till 8th element from last(as a result you have to get:
pro
) - print elements sliced from index -8 to -3(as a result you have to get:
grammi
) - print elements in reverse using slice operation(as a result you have to get:
gnimmargorp
).
Thanks for your feedback!
Negative Indexing
# Creating a string string = 'codefinity' print("Initial string: ", string) string_1 = string[:-7] print("Elements till 7th element from last: ", string_1) string_2 = string[-7:-4] print("Elements from index -7 to -5:",string_2) string_3 = string[::-1] print("String in reverse order: ", string_3)
Swipe to show code editor
You have such a string programming
.
You have to carry out these steps:
- print elements sliced till 8th element from last(as a result you have to get:
pro
) - print elements sliced from index -8 to -3(as a result you have to get:
grammi
) - print elements in reverse using slice operation(as a result you have to get:
gnimmargorp
).
Thanks for your feedback!
Negative Indexing
# Creating a string string = 'codefinity' print("Initial string: ", string) string_1 = string[:-7] print("Elements till 7th element from last: ", string_1) string_2 = string[-7:-4] print("Elements from index -7 to -5:",string_2) string_3 = string[::-1] print("String in reverse order: ", string_3)
Swipe to show code editor
You have such a string programming
.
You have to carry out these steps:
- print elements sliced till 8th element from last(as a result you have to get:
pro
) - print elements sliced from index -8 to -3(as a result you have to get:
grammi
) - print elements in reverse using slice operation(as a result you have to get:
gnimmargorp
).
Thanks for your feedback!
# Creating a string string = 'codefinity' print("Initial string: ", string) string_1 = string[:-7] print("Elements till 7th element from last: ", string_1) string_2 = string[-7:-4] print("Elements from index -7 to -5:",string_2) string_3 = string[::-1] print("String in reverse order: ", string_3)
Swipe to show code editor
You have such a string programming
.
You have to carry out these steps:
- print elements sliced till 8th element from last(as a result you have to get:
pro
) - print elements sliced from index -8 to -3(as a result you have to get:
grammi
) - print elements in reverse using slice operation(as a result you have to get:
gnimmargorp
).