상세 컨텐츠

본문 제목

Array

Python

by techbard 2023. 5. 10. 23:09

본문

반응형

 

Array can be handled in Python by a module named array.
They can be useful when we have to manipulate only a specific data type values.
A user can treat lists  as arrays.
However, user cannot constraint the type of elements stored in a list.
If you create arrays using the array module, all elements of the array must be of the same type.

 

### 파이썬 배열 생성 예
"""
syntax: array(data_type, value_list)
"""

import array as arr

def main():
    a = arr.array('i', [1, 2, 3])
    print('The new created array is: ', end='')
    for i in range(len(a)):
        print(a[i], end=' ')

    print()

    b = arr.array('d', [2.5, 3.2, 3.3])
    print('The new created array is: ', end='')
    for i in range(len(b)):
        print(b[i], end=' ')

if __name__ == '__main__':
    main()

#결과
The new created array is: 1 2 3 
The new created array is: 2.5 3.2 3.3
반응형

관련글 더보기

댓글 영역