https://www.w3schools.com/python/python_datatypes.asp
Python Data Types
Python Data Types Built-in Data Types In programming, data type is an important concept. Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default, in these categories:
www.w3schools.com
파이썬은 변수를 정의할 때 데이터 타입을 명시하지 않지만 그렇다고 데이터 타입이 없는 것은 아니다. 오히려 희한한 데이터 타입이 많다.
Text Type: | str |
Numeric Types: | int, float, complex |
Sequence Types: | list, tuple, range |
Mapping Type: | dict |
Set Types: | set, frozenset |
Boolean Type: | bool |
Binary Types: | bytes, bytearray, memoryview |
반 이상은 이게 뭔가 싶은 것들이다.
1. 데이터 타입 알아내기: type()
데이터 타입을 알아내기 위해서는 type() 함수를 사용하면 된다.
x = 5
print(type(x))
2. 데이터 타입 결정
데이터 타입은 변수를 정의할 때 자동으로 결정된다.
x = "Hello World" | str |
x = 20 | int |
x = 20.5 | float |
x = 1j | complex |
x = ["apple", "banana", "cherry"] | list |
x = ("apple", "banana", "cherry") | tuple |
x = range(6) | range |
x = {"name" : "John", "age" : 36} | dict |
x = {"apple", "banana", "cherry"} | set |
x = frozenset({"apple", "banana", "cherry"}) | frozenset |
x = True | bool |
x = b"Hello" | bytes |
x = bytearray(5) | bytearray |
x = memoryview(bytes(5)) | memoryview |
원한다면 데이터 타입을 명시해줄 수도 있다.
x = str("Hello World") | str |
x = int(20) | int |
x = float(20.5) | float |
x = complex(1j) | complex |
x = list(("apple", "banana", "cherry")) | list |
x = tuple(("apple", "banana", "cherry")) | tuple |
x = range(6) | range |
x = dict(name="John", age=36) | dict |
x = set(("apple", "banana", "cherry")) | set |
x = frozenset(("apple", "banana", "cherry")) | frozenset |
x = bool(5) | bool |
x = bytes(5) | bytes |
x = bytearray(5) | bytearray |
x = memoryview(bytes(5)) | memoryview |
'컴퓨터' 카테고리의 다른 글
Python Casting 파이썬 형 변환 (0) | 2019.09.06 |
---|---|
Python Numbers 파이썬 수치형 (0) | 2019.09.06 |
Python Variables 파이썬 변수 (0) | 2019.09.05 |
Python Comment 파이썬 주석 (0) | 2019.09.05 |
Python Syntax 파이썬 기본 문법(실행, 들여쓰기) (0) | 2019.09.05 |