변수 선언, 변수에 담겨 있는 값 변경하기

CODEDRAGON Development/Python

반응형



 

 

변수 선언

변수에 값을 대입하여 변수를 선언해 줍니다.

 

변수명 = 변수에 저장할

 

>>> a = 10

>>> print (a + 5)

15

>>> b = 20

>>> print ( b + 5)

25

>>> print (a + b)

30

 

 

 

 

 

 

변수에 담겨 있는 변경하기

>>> n = 50

>>> print (n)

50

>>> m = 60

>>> print (m)

60

>>> print ( n+m)

110

>>> print (n)

50

>>> n = 100

>>> print (n+m)

160

>>> print (n)

100

 

 

변수의 값으로 숫자 문자를 비롯한 다양한 자료형이 있습니다.

>>> str = "python"

>>> print (str)

python

>>> print ("I love " + str)

I love python

>>> str1, str2 = 'My', 'Python'

>>> print (str1)

My

>>> print (str2)

Python

>>> print (str1 + str2)

MyPython

 

 

 

 



반응형