본문 바로가기
Programming Languages/Python

[Python Examples] type(): int, float, str 예제 코드

by Henry Cho 2022. 9. 29.

type(): int, float, str 예제 코드

포스트 난이도: HOO_Intern


# type()

var =10
print(type(var))

var_float =10.52
print(type(var_float))

introduce = "Hello I'm HOO."
print(type(introduce))

alphabet = "A"
print(type(alphabet))

<class 'int'>
<class 'float'>
<class 'str'>
<class 'str'>

파이썬에서 type() function을 통해 데이터 타입(data type)을 확인할 수 있다. print()를 사용하지 않고 type()만 사용하여도 어떤 data type인지 출력이 된다. 하지만 print()를 사용하면 <class  'data type'>으로 출력된다.

 

위의 예제 코드를 살펴보면 int, float, str 등이 type()를 통해서 출력되는 걸 확인할 수 있다. data type을 별도로 지정하지 않아도 파이썬에서는 어떤 data type의 값인지가 자동으로 지정되는 것 또한 type()으로 확인할 수 있다.


 

728x90

댓글