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]
No comments:
Post a Comment