٩(๑•̀o•́๑)و

Variable 본문

Python

Variable

11mia 2020. 7. 28. 01:12

# 변수 규칙

  • 영문 문자와 숫자 사용 가능
  • 대소문자 구분
  • 문자부터 시작해야 함
  • _로 시작 가능
  • 특수문자 사용 불가
  • 파이썬의 키워드 사용 불가
>>> x = 10
>>> y = 'hello'
>>> print(x)
10
>>> print(y)
hello
>>> type(x)
<class 'int'>
>>> type(y)
<class 'str'>
>>> x1, y1 = 10, 'hello'
>>> print(x1, y1)
10 hello
>>> type(x1)
<class 'int'>
>>> type(y1)
<class 'str'>
>>> x, y = 10, 20
>>> x, y = y,x
>>> print(x, y)
20 10
>>> print(x)
20
>>> del x
>>> print(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
>>> x = None # null과 동일
>>> print(x)
None
>>> type(x)
<class 'NoneType'>
>>> x = 10
>>> x += 2 # x = x+2
>>> x
12
>>> x = input()
hello world
>>> print(x)
hello world
>>> y = input('입력 : ')
입력 : input
>>> print(y)
input
>>> a = int(input('숫자1 : '))
숫자1 : 3
>>> b = int(input('숫자2 : '))
숫자2 : 4
>>> a+b
7
>>> a,b = input('input1, input2 : ').split() #공백으로 구분
input1, input2 : 3 4
>>> print(a); print(b);
3
4
>>> a, b = input('input1, input2 : ').split(',')
input1, input2 : 3,4
>>> print(a); print(b);
3
4
>>> a, b = map(int, input('input1, input2 : ').split())
input1, input2 : 3 5
>>> a+b
8
>>> a, b = map(int, input('input1, input2 : ').split(','))
input1, input2 : 4, 6
>>> a+b
10
>>>

 

# 파이썬에서의 변수와 값 : 파이썬은 값 자체도 객체. 따라서 변수는 객체를 가리키는 방식을 사용함.

>>> x = 10
>>> y = 10
>>> print(x is y)
True

'Python' 카테고리의 다른 글

Boolean  (0) 2020.07.28
print  (0) 2020.07.28
숫자 연산  (0) 2020.07.28
주석 처리  (0) 2020.07.28
Python & PyCharm Setting  (0) 2020.07.28