[리눅스] Python 에서 변수의 데이터형 알아내기

2023. 8. 1. 23:10Python/관리 팁

작성일 : 2017. 3. 9

 

Python 은 자바와 다르게 print 문에서 str 과 다른 데이터형 변수를 섞어서 출력할 수 없다. 오토박싱을 지원안한다고 해야 하나?

 

TypeError("cannot concatenate 'str' and 'list' objects",) <== 이런 경고문을 출력한다.

 

그래서 복잡한 코드를 피하고 단지 변수형만 출력하려면 type(변수명) 함수를 print 뒤에 넘기면 된다.

 

소스)

print 'Output_dir : '
print type(Output_dir)


print 'Sample_id : '
print type(Sample_id)


print 'Temp_dir : '
print type(Temp_dir)


실행결과)

Output_dir :
<type 'str'>

Sample_id :
<type 'str'>

Temp_dir :
<type 'str'>

eagle_out :
<type 'str'>