Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

How can I declare an array in Python?

I could not find any reference to arrays in the documentation.

1 Answer

0 votes
by (119k points)

Here are the examples to create and basic in-built functions to handle and alter the array:

array_name = []  #to declare an empty array

array_1 = [ '2', '3', '4', '7', '9'] #to declare an array with numericals

print( "First Element:", array_1 [0]) #returns the first element of an array

print( "Last Element:", array_1 [-1]) #returns the last element of an array

print( "Length of the array:", len(array_1)) #returns length of an array

Array is mutable i.e. can modify after declaring variable. There are a lot of in-built libraries like append(), insert(), etc. to alter the array.

You can go through this Python Tutorial to learn more about Arrays and in-built functions to handle arrays.

Related questions

0 votes
2 answers
0 votes
1 answer
asked Jul 8, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...