Input Data를 받으면 항상 'String'으로 데이터 타입을 받아오게 되는데,
그럴때 Casting을 사용할 수 있다. 한마디로 데이터 타입(Type)을 바꾸는 것이다
int() >>str()
weight1 = '60' # a string
weight2 = 170 # an integer
# add 2 integers
total_weight = int(weight1) + weight2
# Weight1은 String 타입이기에 integer Type의 값과 합이 되지 않으므로 int()를 통하여 Integer 타입으로 변환 시켜서 계산을 할 수 있다.
print(total_weight)
>> 230
'IT > Python' 카테고리의 다른 글
[파이썬] List 관련 (Python) (0) | 2020.06.29 |
---|---|
[파이썬] Slicing (자르기) (0) | 2020.06.29 |
[파이썬] if, elif, else 구문 (1) | 2020.06.29 |
[파이썬] Boolean string methods (Yes or No) (0) | 2020.06.29 |
[파이썬] Pandas Cheat Sheet (0) | 2020.06.17 |