본문 바로가기

Python

Python_G-003 : Variable Type

Variable Type Description Example
int integer -3, 0, 34, ...
float real -23.43, 4.56 ...
str string "hello"
bool True or False True or 1 , False or 0
list sequence [1, 2, 3, 'four', 5.3]
tuple sequence (1, 2, 3, 'four', 5.3)
dict sequence {'key': 'value'}  
ex)  {'name': 'Alice', 'age': 30, 'profession': 'Engineer'}
set sequence {1, 2, 3, 'four', 5.3}

 

 

List vs (1D) array

Type Built-in Python data type Provided by the NumPy library
Flexibility Can contain elements of different types Typically contains elements of a single data type
Operations General-purpose operations
(appending, slicing)
Optimized for numerical operations
(element-wise operations, mathematical functions)
Performance Generally slower
for numerical operations
Generally faster and more efficient
for numerical operations
Syntax my_list = [1, 2, 3, 4, 5] import numpy as np
my_array = np.array(  [1, 2, 3, 4, 5]  )