Showing posts with label Declare Arrays in Python. Show all posts
Showing posts with label Declare Arrays in Python. Show all posts

Wednesday, June 16, 2021

Declare Arrays in Python

Declare Arrays in Python

A Python List can be considered as a Dynamic Array. The following examples present how to declare an Array in Python.


arr1 = [0] * 8
print(arr1)
# Output: [0, 0, 0, 0, 0, 0, 0, 0]

arr2 = [""] * 8
print(arr2)
# Output: ['', '', '', '', '', '', '', '']

arr3 = [None] * 8
print(arr3)
# Output: [None, None, None, None, None, None, None, None]

arr4 = [None for i in range(0, 8)]
print(arr4)
# Output: [None, None, None, None, None, None, None, None]