Python-Quizzes | Python List Quiz | Question 12
Question 12: Find the output of the following program:
list = [ 'python' , 'learning' , '@' , 'Geeks' , 'for' , 'Geeks' ] print ( list [ 0 : 6 : 2 ]) |
(A) [‘python’, ‘@’, ‘for’]
(B) [‘Geeks’, ‘Geeks’, ‘learning’]
(C) [‘python’, ‘learning’, ‘@’, ‘Geeks’, ‘for’, ‘Geeks’]
(D) [‘python’, ‘Geeks’]
Answer: (A)
Explanation: In python list slicing can also be done by using the syntax listName[x:y:z] where x means the initial index, y-1 defines the final index value and z specifies the step size. If anyone of the values among x, y, and z is missing the interpreter takes the default value.
Quiz of this Question