Wecode에서 배운 파이썬 기본 문법에 대한 정리입니다.
변수에 저장할 수 있는 값(value)은 string 뿐만이 아니다.
다음 처럼 숫자 값도 저장 할 수 있다.
age = 23 print(age) ## 23 출력
age = "23" next_year = age + 1 print(next_year)
위 코드를 실행 시키면 다음과 같은 에러가 발생된다:
Traceback (most recent call last):
File "python", line 2, in
TypeError: must be str, not int
위 코드가 제대로 작동하게 하려면 age 의 값을 string 이 아닌 숫자로 변경하면 된다.
age = 23 next_year = age + 1 print(next_year)
위의 코드를 실행 시켜면 24가 출력된다.
숫자 값은 정수(integer) 이외에도 부동 소수점(floating) 숫자 값도 가능하다.
price = 24.90
음수(negative number)도 가능하다.
stock_profit_percentage = -10