3. Predict the output of the following code snippet?
a = [1,2,3,4,5)
print(a[3:0:-1])
Answers
Answered by
0
[4, 3, 2]
Predict the output of the following code snippet
Python Code
a = [1,2,3,4,5]
print(a[3:0:-1])
Output
[4, 3, 2]
- Accessing an array element is the same as using an array index. An array element's index number can be used to access it. Since NumPy array indexes begin at 0, the first element has index 0, the second has index 1, and so on.
- In the Python programming language, the for loop and range() functions can be used to initialise an array with the default value. When given a number as an input, the range() method in Python returns a sequence of numbers that starts at 0 and ends with a particular number, incremented by 1 each time.
- In Python, as in all other programming languages and in all of computing, indexing begins at 0. It's critical to keep in mind that counting begins at 0 rather than 1 You must write the array's name first, followed by square brackets, in order to access an element. Put the item's index number between square brackets.
#SPJ2
Similar questions