python 문법 오류나는 이유

조회수 3498회
print("당신이 태어난 년도를 입력하세요.")
birth-year = int(input())
age = 2017 - birth-year + 1

여기서 2번째줄에서 birth-year가 can't assign to operator라는데 왜 그런지 모르겟어요ㅠㅠ

  • birth_year 이렇게 써야 되는거 아닌가용..? 저도 배운지 얼마 안되서 잘모르긴해요ㅠㅠ 알 수 없는 사용자 2019.4.3 23:03

1 답변

  • 변수명으로 가능한 경우는 아래와 같습니다.

    • A variable name must start with a letter or the underscore character
    • A variable name cannot start with a number
    • A variable name can only contain alpha-numeric characters, unicode(for python 3.x) and underscores (A-z, 0-9, and _ )
    • Variable names are case-sensitive (age, Age and AGE are three different variables)

    underscore 만 가능하지 마이너스 기호는 변수명에 사용할 수 없습니다.

    즉 질문상의 코드인 birth-year 는 birth 변수에서 year 변수를 빼는 코드가 됩니다.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)