Anamika Jain Anamika Jain - 1 year ago 101
Python Question

How to store a part of an array in different array in python

Let's say I have an array

A=[1 2 3 2 4 5 6]

Now i need to store first 3 values of array A into array B

I am doing


but I am unable to get any output.

Answer Source

You should consider to use slices

a = [1, 2, 3, 4, 5]
b = a[:3]

print b #print(b) for Python 3.x


[1, 2, 3]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download