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
'Programming Languages > Python' 카테고리의 다른 글
[Python Examples] 파이썬 텍스트 파일 만들기: open(), %pycat (0) | 2022.10.07 |
---|---|
[Python Examples] 파이썬 format() 예제 (0) | 2022.10.07 |
[Python Examples] print(sep=) 예제 코드, print(mm,dd, yyyy, sep='-') (0) | 2022.09.29 |
[Python Example] print(), print(sep=), print(c1+c2+c3..) 차이점 (0) | 2022.09.29 |
[Python] 파이썬 \r, \n, \b (0) | 2022.09.28 |
댓글