Negative Indexing
12345678910# 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)
Uppgift
Swipe to start coding
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
).
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 7
single
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 3.85
Negative Indexing
Svep för att visa menyn
12345678910# 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)
Uppgift
Swipe to start coding
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
).
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Awesome!
Completion rate improved to 3.85Avsnitt 3. Kapitel 7
single