Computer Science, asked by deepikasnaik8, 3 months ago

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

Answered by Equestriadash
6

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

Answered by TheBestWriter
2

 \huge \mathrm{ \underline { \gray{question}}}

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])

 \mathrm{ \huge{ \underline{ \gray{answer}}}}

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

Similar questions