Write the output on the basis of list1.
list1 =['Red','Green','Blue','Cyan', 'Magenta','Yellow','Black'] 4
I print(list1[2:6])
II print(list1[2:20])
III print(list1[7:2])
IV print(list1[0:6:2])
V print(list1[::-1])
Answers
Given list:
list1 = ['Red', 'Green', 'Blue', 'Cyan', 'Magenta', 'Yellow', 'Black']
Outputs:
1. print(list1[2:6])
- ['Blue', 'Cyan', 'Magenta', 'Yellow']
#prints the elements from index position 2 till 6
2. print(list1[2:20])
- ['Blue', 'Cyan', 'Magenta', 'Yellow', 'Black']
#prints the elements from index position 2 till the last element
NOTE: If the ending index position given in the slice is out of range, it'll print till the last element and will NOT render an error.
3. print(list1[7:2])
- []
#prints an empty list since the starting value cannot be greater than the stop value
4. print(list1[0:6:2])
- ['Red', 'Blue', 'Magenta']
#prints the elements from index position 0 till 6, skipping 2 values in between
5. print(list1[::-1])
- ['Black', 'Yellow', 'Magenta', 'Cyan', 'Blue', 'Green', 'Red']
#prints the list in reverse order since the step value is negative
Write the output on the basis of list1.
list1 =['Red','Green','Blue','Cyan', 'Magenta','Yellow','Black'] 4
( I )print(list1[2:6])
( II )print(list1[2:20])
( III ) print(list1[7:2])
( IV ) print(list1[0:6:2])
( V ) print(list1[::-1])
list1 = ['Red', 'Green', 'Blue', 'Cyan', 'Magenta', 'Yellow', 'Black']
Outputs:
1. print(list1[2:6])
['Blue', 'Cyan', 'Magenta', 'Yellow']
#prints the elements from index position 2 till 6
2. print(list1[2:20])
['Blue', 'Cyan', 'Magenta', 'Yellow', 'Black']
#prints the elements from index position 2 till the last element
NOTE:
If the ending index position given in the slice is out of range, it'll print till the last element and will NOT render an error.
3. print(list1[7:2])
[]
#prints an empty list since the starting value cannot be greater than the stop value
4. print(list1[0:6:2])
['Red', 'Blue', 'Magenta']
#prints the elements from index position 0 till 6, skipping 2 values in between
5. print(list1[::-1])
['Black', 'Yellow', 'Magenta', 'Cyan', 'Blue', 'Green', 'Red']
#prints the list in reverse order since the step value is negative
Learn more:-
https/brainly.in/question/38292927
https/brainly.in/question/388199191
https/brainly.in/question/37282811