Python

[Python] 파이썬 자료형 알아내는 함수 type()

Let it out 2024. 5. 7. 06:13

함수 원형

type() 함수안에다가 변수명이나 숫자, 문자를 작성해주면 된다.

type()

 

 

예제

type() 함수를 print 함수로 출력해주면 자료형이 나온다.

a = 10
print(type(a))      # int
print(type(111))    # int
print(type(111.1))  # float
print(type("111"))  # string
print(type(True))   # bool
print(type(3+4j))   # complex

 

결과

<class 'int'>
<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>
<class 'complex'>

 

 

자료형 정리

int : 정수형

float : 실수형

string : 문자열

bool : 참, 거짓

complex : 복소수

 

반응형