KamilJ
0
Q:

array in array python

array = ["1st", "2nd", "3rd"];
#prints: ['1st', '2nd', '3rd']
34
#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
#You can put multiple arrays in one array
tests = [[1,2,3],["r",22,33]]
#prints: [[1,2,3],['r',22,33]]
4
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
cars = ["Ford", "Volvo", "BMW"]
0

New to Communities?

Join the community