John Doe
0
Q:

python arrays

array = ["1st", "2nd", "3rd"];
#prints: ['1st', '2nd', '3rd']
34
array = [1,2,3,4,5]
print(array,array[0],array[1],array[2],array[3],array[4]

#Output#
#[1,2,3,4,5] 1 2 3 4 5
19
#Setting The Array:#

array = [250,630,221] #You can have as many items as you want#

#Printing The Whole Array:#

print(array)
#output = [250, 630, 221,]#

#Printing Individual Items From The Array:#

print(array[0])
#output = 250#

print(array[1])
#output = 630#

print(array[2])
#output = 221#
#array[0] is the 1st array item, array[1] the 2nd, and so on#

#Printing Multiple Items From The Array:#

print(array[2],array[0])
#output = 221#
8
import array as arr

numbers_list = [2, 5, 62, 5, 42, 52, 48, 5]
numbers_array = arr.array('i', numbers_list)

print(numbers_array[2:5]) # 3rd to 5th
print(numbers_array[:-5]) # beginning to 4th
print(numbers_array[5:])  # 6th to end
print(numbers_array[:])   # beginning to end
1
array = [1, 2, 3, 4]

array.append(5)

for i in array:
  print(i)
1
cars = ["Ford", "Volvo", "BMW"]
0
arr = [1,"two",3.0,"four",5]
-1

New to Communities?

Join the community