View

TIL 11 | PYTHON_Variables

Melody:) 2021. 8. 5. 17:05

Variables_변수

어떠한 특정 값을 저장하고 있는 '명사'


01 변수에 값 저장하기 

👉 변수 =  값 

 

02 변수 이름 법칙 

  • 변수 이름은 영어 알파벳과 숫자 그리고 underscore(_) 으로만 구성
  • 변수 이름 첫글자는 알파벳이나 underscore(_)로만 시작
    주의! 숫자로 시작될 수 없음
  • 영어 알파벳은 대문자와 소문자가 구분됨.
  • 올바른 변수 이름 : name, _name, my_name, myName
  • 잘못된 변수 이름: 7name, my name

🍯TIP  변수의 이름을 지정할 때는 코드의 가독성을 위하여 변수에 저장된 값들에 맞게 변수의 이름을 정하는 것이 좋다.

 

03 데이터 타입에 따른 ""(Double Quotes)의 옳바른 사용

age = "23"
next_year = age + 1
 
print(next_year)

 #age에 저장된 데이터는 문자열(""로 묶임)이므로 아래 같은 출력 에러 발생)

Traceback (most recent call last):   
    File "python", line 2, in <module> 
TypeError: must be str, not int

 

 


 

추가로 공부하면 좋은 것

print(f"""Python was conceived in the late {date} by {python_inventor} at {location} (CWI) in the {country} as a successor to the ABC language (itself inspired by SETL), capable of exception handling and interfacing with the Amoeba operating system. Its implementation began in December 1989.""")

print 문에 사용된 string 포맷은 Literal String Interpolation 포맷
 
https://realpython.com/python-f-strings/ 

 

'PYTHON' 카테고리의 다른 글

TIL 13 | PYTHON_String Concatenation  (0) 2021.08.05
TIL 12 | PYTHON_Math Expressions  (0) 2021.08.05
TIL 10 | PYTHON_Print_DataType  (0) 2021.08.05
PYTHON) 숫자 계산_정수  (0) 2021.07.14
PYTHON) 기본문법  (0) 2021.07.13
Share Link
reply
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31